Immutable Updates to Nested Schema Outputs

Just a question if I'm going down the right path for making immutable updates to outputs from schema.

Here is a simplified case, to try and understand the general case:
import { Data, Schema } from 'effect';

const NameSchema = Schema.String.pipe(Schema.brand('Name'));

class Person extends Schema.Class<Person>('Person')({
  name: NameSchema,
  age: Schema.Number.pipe(Schema.int(), Schema.greaterThan(0)),
  nested: Schema.Data(
    Schema.Struct({ foo: Schema.String, bar: Schema.String }),
  ),
}) {}

const alice = Schema.decodeSync(Person)({
  name: 'Alice',
  age: 1,
  nested: { foo: 'fuz', bar: 'buz' },
});

const otherAlice = new Person({
  ...alice,
  nested: Data.struct({ ...alice.nested, bar: 'bit' }),
});

console.log(otherAlice);


So I have a person alice with a nested field nested.bar that needs to be updated. What I've got there works, and the typescript types help (i.e. tells me to wrap nested in Data.struct)

but wondering if there is a better / more idomatic way to do this?
Was this page helpful?