Fxnk.List (Fxnk v0.1.4) View Source

Fxnk.List are functions for working with lists.

Link to this section Summary

Functions

Returns a list of whatever was passed to it.

Takes a list of maps and a key, returns a list of values in the key over all the maps

Takes two lists and returns a map where the keys are the elements from the first list and the values are the elements from the second.

Takes two lists and returns a map where the keys are the elements from the second list and the values are the elements from the first.

reduce_right/3 takes a list of args, an initial value and a function and returns a single value.

zip_map/2 is a lot like Enum.zip/2, but instead of returning a list of tuples, it returns a list of maps, where the keys are the second list passed in.

Link to this section Functions

Specs

of(any()) :: [any(), ...]

Returns a list of whatever was passed to it.

Example

iex> Fxnk.List.of(3)
[3]
iex> Fxnk.List.of([])
[[]]

Specs

pluck([map(), ...], binary() | atom()) :: [any()]

Takes a list of maps and a key, returns a list of values in the key over all the maps

Examples

iex> list = [%{user_id: "1234"}, %{user_id: "4567"}, %{user_id: "6789"}]
iex> Fxnk.List.pluck(list, :user_id)
["1234", "4567", "6789"]
Link to this function

reduce_map(values, keys)

View Source

Specs

reduce_map([any(), ...], [any()]) :: %{required(any()) => any()}

Takes two lists and returns a map where the keys are the elements from the first list and the values are the elements from the second.

Examples

iex> Fxnk.List.reduce_map([1, 2, 3], [:one, :two, :three])
%{one: 1, two: 2, three: 3}
Link to this function

reduce_map_right(keys, values)

View Source

Specs

reduce_map_right([any()], [any(), ...]) :: %{required(any()) => any()}

Takes two lists and returns a map where the keys are the elements from the second list and the values are the elements from the first.

Examples

iex> Fxnk.List.reduce_map_right([:one, :two, :three], [1, 2, 3])
%{one: 1, two: 2, three: 3}
Link to this function

reduce_right(args, initial, func)

View Source

Specs

reduce_right([any()], any(), function()) :: any()

reduce_right/3 takes a list of args, an initial value and a function and returns a single value.

Like reduce, it applies the function to each of the arguments, and accumulating the result, except it does it right to left.

Examples

iex> Fxnk.List.reduce_right([1,2,3,4,5], 0, fn a, b -> a + b end)
15

Specs

zip_map([any()], [any()]) :: [%{required(any()) => any()}]

zip_map/2 is a lot like Enum.zip/2, but instead of returning a list of tuples, it returns a list of maps, where the keys are the second list passed in.

Examples

iex> Fxnk.List.zip_map(["hello", "world"], ["first", "second"])
[%{"first" => "hello"}, %{"second" => "world"}]