There is syntax sugar for getting a field on a record: .field desugars to \x -> x.field. I was writing some code today where a setter version of that would be nice, maybe something like &field desugars to \field, x -> {x & field}. Useful for being able to pass a getter and setter to a function that can get a field, do some operation on it, then set it.
doSomething x.field (\field -> { x & field})
becomes
doSomething x .field &field
doSomething = \x, get, set -> get x |> someOperation |> set x
Minor savings I know, but helpful if you find yourself having to do this a lot.
This example isn't much shorter than { x & field : doSomething x.field}, but setter functions can be passed around, saved for later use, etc
It's already implemented. Here's an example of using it https://github.com/lukewilliamboswell/roc-ray/blob/d69a1699d3e67e326bc9ed80ad0d2240c13f4d3d/examples/2d_camera.roc#L77
Wow! didn't know that
Yeah, things have been moving fast.
Can we add tuple setters? &0, &1 etc
or is the type system not powerful enough for that right now
i think that would help a lot for big tuples because there's no easy syntax to do that right now
Here was the implementation https://github.com/roc-lang/roc/pull/7002
For a separate Tuple accessor I think that's an interesting idea
Nice!
Luke Boswell said:
For a separate Tuple accessor I think that's an interesting idea
Should i make a new channel for the idea or should it stay in here?
Let's make a new thread
Since it might be contentious, though I don't know
Last updated: Jun 16 2026 at 16:19 UTC