A.Vector.split_with

You're seeing just the function split_with, go back to A.Vector module for more information.

Specs

split_with(t(val), (val -> as_boolean(term()))) :: {t(val), t(val)}
when val: value()

Splits the vector in two vectors according to the given function fun.

Returns a tuple with the first vector containing all the elements in vector for which applying fun returned a truthy value, and a second vector with all the elements for which applying fun returned a falsy value (false or nil).

Returns the same result as filter/2 and reject/2 at once, but only walks the vector once and calls fun exactly once per element.

Runs in linear time.

Examples

iex> vector = A.Vector.new(1..12)
iex> {filtered, rejected} = A.Vector.split_with(vector, fn i -> rem(i, 3) == 0 end)
iex> filtered
vec([3, 6, 9, 12])
iex> rejected
vec([1, 2, 4, 5, 7, 8, 10, 11])