Hi, im interested in implementing the List.update
and List.updater
builtins but I have a few questions.
List.updater
supposed to work? I don't understand what it should do from its type signature updater : List elem, Int -> { elem, new : elem -> List elem }
Int
for the index? Shouldn't they use Nat
?I have some guesses:
Same pr:
probably fine. If they end up being complex, better separate
Int vs Nat: yeah, should be Nat
Function signature: i have stared at it for a bit, and my gut feeling is that we probably want to change the signature. That said, i think i get it now. it takes a list and an index. It returns the element at that index. It also returns a function that when given a element creates a new list that is identical to the original list, but with the element at index updated to the new element passed in.
So kinda like some sort of delayed replace function.
I could be wrong. Really confused about the use case/goal here.
That makes sense for List.updater
to me. Personally not sure of the use case either tbh.
where are these mentioned? :sweat_smile:
I don't actually recognize them!
oh I see - in https://github.com/roc-lang/roc/issues/664
hm, I think we should take those off that list until someone has a use case for them - thoughts?
List.update
i think can be decently useful in roc since otherwise you would have to handle a Result
from List.get
. I think it can be useful in a pinch for something like the AOC problem this year with the monkeys where you needed to modify an item in a set, tho i don't do that very regularly.
List.updater
feels bloated for a standard lib to me.
I don't think I would miss either of these functions if they weren't builtin.
yeah let's just hold off :big_smile:
are there any others you're interested in tackling as a first contribution?
I might take a stab at the result mapping ones listed in #664 cause they look easy, someone just has to do them and write docs and tests.
Nobody wants to write docs and tests :sob:
Last updated: Jul 06 2025 at 12:14 UTC