Excited about not having to think about Lists vs Arrays in the future!
Some of the first things I did when learning Elm was hacking together functions for getting items and deleting items by index from a List, because I hadn't looked into the Array package 😅Having Arrays as the default would have made the experience much smoother.
Btw, why is there no "delete element at index" function built in? Is it perhaps because it can "fail silently"? Ie:
I have an Array of length 3
I do some math wrong and delete index 5 instead of 2
I get the same Array of length 3 back, with no compiler error.
Ah I see. Surely it'll be more efficient than people writing their own though. Here's mine 😅
remove : Int -> List a -> List a
remove index list =
list
|> List.indexedMap Tuple.pair
|> List.filter (\( i, _ ) -> i /= index)
|> List.map Tuple.second
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Excited about not having to think about Lists vs Arrays in the future!
Some of the first things I did when learning Elm was hacking together functions for getting items and deleting items by index from a List, because I hadn't looked into the Array package 😅Having Arrays as the default would have made the experience much smoother.
Btw, why is there no "delete element at index" function built in? Is it perhaps because it can "fail silently"? Ie:
I have an Array of length 3
I do some math wrong and delete index 5 instead of 2
I get the same Array of length 3 back, with no compiler error.
Mostly because it’s inefficient, but that might be fixed in the future
Ah I see. Surely it'll be more efficient than people writing their own though. Here's mine 😅