Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Array.update or similar #61

Closed
mbartlett21 opened this issue Mar 28, 2023 · 1 comment
Closed

Add Array.update or similar #61

mbartlett21 opened this issue Mar 28, 2023 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@mbartlett21
Copy link

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
@robinheghan robinheghan added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Mar 28, 2023
@robinheghan
Copy link
Member

Fixed in upcoming release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants