(Inspired by Elm's .foo
syntax to create a field accessor function)
It would be very useful to support a method call whose target hasn't been specified yet, as a kind of currying. It should support acting as a getter or a setter, so maybe:
.y = {
(x) = x.y
lazy(x) = -> x.y
setter(x) = {(val) = x {+} {y = val}}}
mapper(f) = {(x) = x {+} {y = f(x.y)}}
}
.foo(bar) = [
(x) = x.foo(bar)
lazy(x) = -> x.foo(bar)
setter(x) = ... // ???
}
The setter is useful for higher-order functions where you want to create a function that replaces a field in its parameter with new value.
The mapper transforms the single field to give a new object where just that field was replaced.