Skip to content

API semantics for deep nested evolve calls #932

@jacobg

Description

@jacobg

When trying to evolve a frozen object at a deep level, there is a lot of boilerplate, e.g.,:

foo = attr.evolve(
   foo,
   bar=attr.evolve(
      foo.bar,
      baz=attr.evolve(
         foo.bar.baz,
         qux='whew!'
       )
   )
)

Scala has a similar problem, being that immutable data classes is a normal thing in that language. There is a Scala library developed helped to solve that problem: https://www.optics.dev/Monocle/

Maybe it would be useful to have those sort of semantics for updating frozen attr objects,e.g.:

foo = attr.focus(foo, Foo.bar.baz.qux).modify('yay!')

Any thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions