One thing I find strange that Roc does not have is a way to extend a record.
For example:
get_token! : {key: Str} => {key: Str, token: Str}
get_token! = |conf|
token = get!(conf.key)
{conf extend session: token}
This is a pattern I use all the time in Clojure and Javascript to build up more complex structures. Is there a reason we only have the & in Roc to change values in a record but not extending a record?
I think we chose not to support extending like this because it could be really bad for performance. The old record has to be copied over entirely to a new spot in memory.
Ok good to know the reason but its to bad, I really love that pattern in untyped languages paired with the pipe syntax.
Yeah, I think the recommended alternative would be to use a tag union: [NoToken, Token(Str)]
As a note, we plan to support extending records in the future, but it is pretty low on the backlog.
Last updated: Jul 06 2025 at 12:14 UTC