Hyperlinkv0.8.0-beta.28

Struct

Struct.assignconsteffect/Struct.ts:274
<O extends object>(that: O): <S extends object>(self: S) => Assign<S, O>
<O extends object, S extends object>(self: S, that: O): Assign<S, O>

Merges two structs into a new struct. When both structs share a key, the value from that (the second struct) wins.

When to use

Use when you want { ...self, ...that } with proper types.

Details

The result type is Simplify<Assign<S, O>>.

Example (Merging structs with overlapping keys)

import { pipe, Struct } from "effect"

const defaults = { theme: "light", lang: "en" }
const overrides = { theme: "dark", fontSize: 14 }
const config = pipe(defaults, Struct.assign(overrides))
console.log(config) // { theme: "dark", lang: "en", fontSize: 14 }
combiningAssignevolve
Source effect/Struct.ts:2749 lines
export const assign: {
  <O extends object>(that: O): <S extends object>(self: S) => Assign<S, O>
  <O extends object, S extends object>(self: S, that: O): Assign<S, O>
} = dual(
  2,
  <O extends object, S extends object>(self: S, that: O) => {
    return { ...self, ...that }
  }
)
Referenced by 1 symbols