Hello everybody,
Is it possible to destructure a record to get field "a" and "b" into "a" and "b" variables and also get the whole record into "input" variable? Something like this?
# invalid code
stuff = \{ a ? "default1", b ? "default2" }@input ->
(a, b, input)
I want that so I can recursively call the function with a different field:
stuff = ...
...
# from within the function
stuff { input & a: "bla bla" }
Thank you!
There should be, but the syntax is currently broken
It should be {a, b} as input
You can destructure as the first line of the function instead
stuff = \input ->
{ a ? "default1", b ? "default2" } = input
(a, b, input)
Also, just a prewarning: optional record fields have a really inconvenient bug currently. They only specialize to one selection of optionality (which kinda makes them useless).
This means:
# This works by itself
stuff {a: "something"}
# This still works cause it is also missing b
stuff {a: "something2"}
# This breaks when used with the above due to a compiler bug:
stuff {a: "something3", b: "roc is sad :cry:"}
Do you think this bug is the cause for #7031 and/or #7035?
Yes
Last updated: Jul 06 2025 at 12:14 UTC