This would be useful for making modifications to individual items in an array.
I am currently using the below definition to do this:
{-| Updates the element at the given index using the provided function,
or returns the array unmodified if the index is out of bounds.
arrayUpdate 1 (\a -> a * 10) [ 1, 2, 3 ] == [ 1, 20, 3 ]
arrayUpdate 10 (\a -> a * 10) [ 1, 2, 3 ] == [ 1, 2, 3 ]
-}
arrayUpdate : Int -> (a -> a) -> Array a -> Array a
arrayUpdate i f arr =
case Array.get i arr of
Just v ->
Array.set i (f v) arr
Nothing ->
arr
This would be useful for making modifications to individual items in an array.
I am currently using the below definition to do this: