elm-community / list-extra

Convenience functions for working with List.
http://package.elm-lang.org/packages/elm-community/list-extra/latest
MIT License
135 stars 59 forks source link

Proposal for `removeFirst` function #81

Closed wild-lotus closed 6 years ago

wild-lotus commented 6 years ago

Hi folks, I was just missing a function to remove the first element that satisfies a condition. The same goes for replacing. Their types would be:

removeFirst: (a -> Bool) -> List a -> List a
replaceFirst: (a -> Bool) -> a -> List a -> List a

It could be useful to remove by id (or any other field) from a list of records. What do you think? I would be happy to attempt a PR if you find it suitable.

Chadtech commented 6 years ago

Hey @CarlosGines,

Did you find yourself needing a function like this? What were you trying to do? Those questions are my first thoughts when looking at PRs for list-extra.

wild-lotus commented 6 years ago

Hi @Chadtech,

Sure! Given a list of items, I want to update one of them with the data received from an API request. So I want to find it by id and directly replace it or remove it.

Chadtech commented 6 years ago

Are you sure you need to be using a list at all? If you have unique ids, maybe you need a Dict?

Also, list-extra already contains replaceIf. Do you think that would help in your case? We dont have a removeIf, but I suppose that would be the same as List.filter

wild-lotus commented 6 years ago

You are might, you can just use a Dict for these cases. Ok, thank you!