5 ms·
Lenses seem to be a functional pattern that groups getters and setters into composable functions. Consider pair(a, b) with first(pair) and rest(pair). I can de
by pona-a 2y ago
Lenses seem to be a functional pattern that groups getters and setters into composable functions.
Consider pair(a, b) with first(pair) and rest(pair). I can define first-lens and rest-lens for [get-first, set-first] and [get-rest, set-rest] respectively. I could use them as simple getter/setter groupings with lens-view(rest-lens, pair) or lens-set(first-lens, 4, pair), which isn't so useful by itself, or I can compose then to get third-lens with lens-compose(rest-lens, first-lens), allowing me to lens-set(third-lens, 7, pair) without a nested call.
I just tried to summarize what I could read [1] [2] [3] and I don't claim to entirely understand it, but it's still better than the sibling comment dismissing it as abstract nonsense.
[1] https://docs.racket-lang.org/lens/lens-intro.html https://docs.racket-lang.org/lens/lens-intro.html
[2] https://hackage.haskell.org/package/lenses-0.1.4/docs/Data-Lenses.html https://hackage.haskell.org/package/lenses-0.1.4/docs/Data-L...
[3] https://theswiftdev.com/lenses-and-prisms-in-swift/ https://theswiftdev.com/lenses-and-prisms-in-swift/