Enum.split_with
You're seeing just the function
split_with
, go back to Enum module for more information.
Specs
Splits the enumerable
in two lists according to the given function fun
.
Splits the given enumerable
in two lists by calling fun
with each element
in the enumerable
as its only argument. Returns a tuple with the first list
containing all the elements in enumerable
for which applying fun
returned
a truthy value, and a second list with all the elements for which applying
fun
returned a falsy value (false
or nil
).
The elements in both the returned lists are in the same relative order as they were in the original enumerable (if such enumerable was ordered, like a list). See the examples below.
Examples
iex> Enum.split_with([5, 4, 3, 2, 1, 0], fn x -> rem(x, 2) == 0 end)
{[4, 2, 0], [5, 3, 1]}
iex> Enum.split_with(%{a: 1, b: -2, c: 1, d: -3}, fn {_k, v} -> v < 0 end)
{[b: -2, d: -3], [a: 1, c: 1]}
iex> Enum.split_with(%{a: 1, b: -2, c: 1, d: -3}, fn {_k, v} -> v > 50 end)
{[], [a: 1, b: -2, c: 1, d: -3]}
iex> Enum.split_with(%{}, fn {_k, v} -> v > 50 end)
{[], []}