3 ms·
It's not perhaps a surprise that they're similar to lenses; what you've written is a part of the lens hierarchy (they're setters). This is why people often say
by dwohnitmok 6y ago
It's not perhaps a surprise that they're similar to lenses; what you've written is a part of the lens hierarchy (they're setters). This is why people often say you end up just recreating the lens hierarchy anyways if you work with nested data structures a lot. Lenses just combine getters and setters (so they're just a pair of two functions; libraries like Monocle just give them a name instead of making them a literal pair).
They're nice if you have nested data structures that aren't records (e.g. naked product types a la "MyType Int Int Int").
But yes in general flat records are the way to go (but what about nested message types? Turns out that the lens hierarchy helps there too in the form of prisms. Or it would be nice if Elm had extensible union types so we could have flat message types too...)