mbr / elm-extras / Extras.List

Convenience functions for working with lists.

This module is intended to extend List.Extra, which should be the first place to look for extra functionality.

upsert : (a -> Basics.Bool) -> a -> List a -> List a

Update or insert one item in a list.

Searches a list for the first matching element and replaces it. If no matches are found, appends the element to the end of the rest.

upsert (byKey .id newUser.id) newUser users

If you find yourself using this function often, consider using a Dict and insert instead.