I am just curious what your opinions are on the nice modern JS synax sugar for objects and arrays:
[ ...ListA, ...ListB ]
{ ...props, ...moreProps }
personally I honestly hadn't given it much thought...what do others think?
I wonder how often this would be useful and better than List.append
or a record update
It happens frequently enough in Elm that I do miss this particular feature from JS. Because otherwise I have to put a confusing parentesis before and after my last argument list in a view)
In React I have completely stopped using any append function since this feature.
This feature might make more sense in JS since the JS approach for a "new" object would be {...oldObject, newProp = { ...stuff } }
(Which I would prefer as record update incidentally as a way to onboard js folks hehe)
But my personal opinions on language design hardly matter in the grand scheme of things :laughing:
for completeness, do you have an example from elm where this spreading would be useful?
I'm booted into my work OS right now. In an hour or so I will copy paste some code I am actually using and not making up at the top of my head!
For arrays/lists I'd rather use as then I can continue piping it, or do the concat in the middle after modifying listA
listA
|> List.concat listB
For the other, its syntactic sugar for merging records it seems? What happens when both records have the same key but different values? Do you blindly take the second record? If records get really large this could be nice, but for small records it seems like it might hide the details too much :shrug:
So I think the use case here is a scenario like
Html.div (a ++ b) [ Html.text "foobar" ]
Which because roc does not have a ++
infix operator would actually be
Html.div (a |> List.append b) [ Html.text "foobar" ]
Versus
Html.div [..a, ..b] [ Html.text "foobar" ]
But, I wonder how often this really comes up, and whether you would not rather write
attributes =
a |> List.append b
Html.div attributes [ Html.text "foobar" ]
If the construction of attributes is non-trivial
Maybe you folks are right. I had a look at my code and it wasn't that bad. I think I can just keep piping in case that I have multiple Lists or do a concat. Not worth polluting the language with more syntax. Keep it as small as possible imo
Last updated: Jul 06 2025 at 12:14 UTC