Panex v0.1.0 Panex.Collection
Collection utilities
Link to this section Summary
Functions
Remove all falsy values in collection
This method is like _.difference except that it accepts iteratee which is invoked for each element of array and values to generate the criterion by which they’re compared. The order and references of result values are determined by the first array. The iteratee is invoked with one argument
Return a slice of array excluding elements dropped from the end
Fills a number of elements of a list with initial value
Return a map from a list of pairs
Returns the list dropping its last element
Get intersection from given lists
Find index from right to left
Same as last_index_of/2 but search from the index
Remove all elements that match the pattern in a collection
Link to this section Functions
Remove all falsy values in collection
Examples
iex> compact([1, 2, 3, nil, 4, nil, 5])
[1, 2, 3, 4, 5]
iex> compact(["hello", "hola", false, "bonjour"])
["hello", "hola", "bonjour"]
This method is like _.difference except that it accepts iteratee which is invoked for each element of array and values to generate the criterion by which they’re compared. The order and references of result values are determined by the first array. The iteratee is invoked with one argument
Examples
iex> difference_by([2.1, 1.2], [2.3, 3.4], &Kernel.round/1)
[1.2]
iex> difference_by([%{"x" => 2}, %{"x" => 1}], [%{"x" => 1}], &(&1["x"]))
[%{"x" => 2}]
Iteratee shorthand
iex> difference_by([%{"x" => 2}, %{"x" => 1}], [%{"x" => 1}], "x")
[%{"x" => 2}]
iex> difference_by([%{x: 2}, %{x: 1}], [%{x: 1}], :x)
[%{x: 2}]
Return a slice of array excluding elements dropped from the end.
Examples
iex> drop_right_while([1, 2, 3, 4, 5], &(&1 == 4))
[1, 2, 3]
iex> drop_right_while([%{a: 1, b: 2}, %{a: 2, b: 2}], &(&1.a == 2))
[%{a: 1, b: 2}]
Fills a number of elements of a list with initial value
Examples
iex> fill(5, nil)
[nil, nil, nil, nil, nil]
iex> fill(3, "hi")
["hi", "hi", "hi"]
Return a map from a list of pairs
Examples
iex> from_pairs([[:a, 1], [:b, 2]])
%{a: 1, b: 2}
iex> from_pairs([["vn", "Xin chao"], ["us", "hello"]])
%{"us" => "hello", "vn" => "Xin chao"}
Get intersection from given lists.
Examples
iex> intersection([1, 2, 3, 4], [2, 3])
[2, 3]
iex> intersection(["index", "carousel", "header", "footer"], ["header", "footer"])
["header", "footer"]
Find index from right to left.
Examples
iex> last_index_of([1, 1, 3, 4, 2], 4)
3
iex> last_index_of([1, 9, 3, 1, 2], 4)
nil
Same as last_index_of/2 but search from the index.
Examples
iex> last_index_of([1, 1, 3, 4, 2], 4, 2)
3
iex> last_index_of("abbcd" |> String.graphemes, "b", 3)
nil