Skip to content

deleteWith function & friends #242

Description

@flip111

A lot of functions like delete require an index. A lot of times that index was not stored (which would also get updated as the array would change) but has to be refound with findIndex. When you use findIndex and immediately after use delete you know you are guaranteed an index that is not out of bounds. Could "with" functions be added that do this?

deleteWith :: forall a. (a -> Boolean) -> Array a -> Maybe (Array a)
deleteWith pred array = map (\idx -> unsafeDeleteAt idx array) (findIndex pred array)

It would make sense to have the unsafe implementations for them available, at least internally in the array library #167

One could argue that if you do this you are better off using a Map. But i think people will want to use an array plenty of times anyway.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions