KitchenSink v1.3.5 KitchenSink.List View Source
this module is for List functions
Link to this section Summary
Functions
Creates an indexed list from a list of maps using a key_function or a path.
If a path is given then the Access
module will be used
Takes a list of maps, transforms it into a map of maps with their value being the value_key. Basically making a look-up table
A convenient version of what is perhaps the most common use-case for map: extracting a list of property values
Link to this section Functions
Creates an indexed list from a list of maps using a key_function or a path.
If a path is given then the Access
module will be used.
This function is very similar to group_by
, however the values will not be
grouped. There should be a 1-to-1 mapping for the key_fun to item in the list.
For different mapping ratio duplicate keys will be dropped, according to
Map.new/1
logic
Examples
iex> [
...> %{name: :a, other: 1},
...> %{name: :b, other: 4}
...> ] |> index_by(:name)
%{
a: %{name: :a, other: 1},
b: %{name: :b, other: 4}
}
index_on([map], [any], any) :: map
Takes a list of maps, transforms it into a map of maps with their value being the value_key. Basically making a look-up table.
Examples
iex> [
...> %{a: 1, b: "x"},
...> %{a: 2, b: "y"},
...> %{a: 3, b: "z"}
...> ] |> index_on([:a], :b)
%{
%{a: 1} => "x",
%{a: 2} => "y",
%{a: 3} => "z"
}
iex> [
...> %{a: 1, b: "x"},
...> %{a: 2, b: "y"},
...> %{a: 3, b: "z"}
...> ] |> index_on(:a, :b)
%{
%{a: 1} => "x",
%{a: 2} => "y",
%{a: 3} => "z"
}