Swiss.List (swiss v3.11.0) View Source

Link to this section Summary

Functions

Replaces a value in a list at the position indicated by the given predicate.

Link to this section Functions

Link to this function

replace_with(list, value, finder)

View Source

Specs

replace_with(list :: [any()], value :: any(), finder :: (any() -> boolean())) ::
  [any()]

Replaces a value in a list at the position indicated by the given predicate.

The predicate receives list values as its sole argument and should return true when the value to be replaced is found.

When a value isn't found, list is returned as is.

Examples

iex> Swiss.List.replace_with([1, 2, 3], 5, &(&1 == 2))
[1, 5, 3]

iex> Swiss.List.replace_with([1, 2, 3], 5, &(&1 == 5))
[1, 2, 3]