PassiveSupport.List (passive_support v0.8.3)

Functions for working with lists.

Link to this section Summary

Functions

Returns a copy of list with any nil values removed

Performs the provided function on every non-nil value while removing nil values. If also_filter_result is passed, then any nil values that would be returned from the function are not injected into the list.

Returns a new list of [item | list] An antonym to hd.

Link to this section Functions

Specs

compact(list()) :: list()

Returns a copy of list with any nil values removed

Examples

iex> compact([1,nil,3])
[1, 3]

iex> compact([false, nil, nil, "hi"])
[false, "hi"]
Link to this function

compact_map(list, fun, options \\ [])

Specs

compact_map(list(), (... -> any()), [{:also_filter_result, boolean()}]) ::
  list()

Performs the provided function on every non-nil value while removing nil values. If also_filter_result is passed, then any nil values that would be returned from the function are not injected into the list.

Examples

iex> compact_map([1,2,nil,4], &(&1 * 2))
[2,4,8]

iex> compact_map([nil, "   ", {}, 0], &PassiveSupport.Item.presence/1, also_filter_result: true)
[0]

iex> compact_map([nil, false, 0], &(&1), also_filter_result: true)
[false, 0]
Link to this function

cons(list, item)

Specs

cons(list(), any()) :: list()

Returns a new list of [item | list] An antonym to hd.

Examples

iex> cons([2,3], 1)
[1,2,3]
iex> [2,3] |> cons(1) |> cons(0)
[0,1,2,3]