Minmaxlist

Adds min_list_by/2, max_list_by/2 and min_max_list_by/2 that’s not in Enum.

Summary

Functions

Returns list of entries that gives the maximum value as calculated by the given function. Returns empty list if the collection is empty

Returns list of entries that gives the minimum value as calculated by the given function. Returns empty list if the collection is empty

Returns a tuple with two lists of entries that give minimum & maximum values respectively as calculated by the given function. Returns a tuple of two empty lists if the collection is empty

Types

element :: any

Functions

max_list_by(collection, fun)

Specs

max_list_by(t, (element -> any)) :: list

Returns list of entries that gives the maximum value as calculated by the given function. Returns empty list if the collection is empty.

iex> [1, 2, 3, 4, 5, 6] |> Minmaxlist.max_list_by(&(rem(&1,3)))
[2, 5]
iex> [] |> Minmaxlist.max_list_by(&(rem(&1,3)))
[]
min_list_by(collection, fun)

Specs

min_list_by(t, (element -> any)) :: list

Returns list of entries that gives the minimum value as calculated by the given function. Returns empty list if the collection is empty.

iex> [1, 2, 3, 4, 5, 6] |> Minmaxlist.min_list_by(&(rem(&1,3)))
[3, 6]
iex> [] |> Minmaxlist.min_list_by(&(rem(&1,3)))
[]
min_max_list_by(collection, fun)

Specs

min_max_list_by(t, (element -> any)) :: {list, list}

Returns a tuple with two lists of entries that give minimum & maximum values respectively as calculated by the given function. Returns a tuple of two empty lists if the collection is empty.

iex> [1, 2, 3, 4, 5, 6] |> Minmaxlist.min_max_list_by(&(rem(&1,3)))
{[3, 6], [2, 5]}
iex> [] |> Minmaxlist.min_max_list_by(&(rem(&1,3)))
{[], []}