View Source Lens2.Lenses.Filter (Lens 2 v0.2.1)
Lenses that reduce a set of pointers into a smaller set of pointers.
Consider a use of, say, Enum.filter
:
iex> [-2, -1, 0, 1, 2] |> Enum.filter(& &1 > 0)
[1, 2]
Functions in this module convert such a function into a lens that will (eventually) apply the same filter to already-selected elements of a container.
iex> lens = Lens.keys([:a, :c]) |> Lens.filter(& &1 > 0)
iex> container = %{a: 1, b: 9, c: -1}
iex> Deeply.get_all(container, lens)
[1]
iex> Deeply.update(container, lens, & -1111 * &1)
%{a: -1111, b: 9, c: -1}
Summary
Functions
Returns a lens that focuses on a subset of elements focused on by the given lens that satisfy the given condition.
Returns a lens that focuses on a subset of elements focused on by the given lens that don't satisfy the given condition.
Functions
Returns a lens that focuses on a subset of elements focused on by the given lens that satisfy the given condition.
@spec filter(Lens2.lens(), (any() -> boolean())) :: Lens2.lens()
@spec reject(Lens2.lens(), (any() -> boolean())) :: Lens2.lens()
Returns a lens that focuses on a subset of elements focused on by the given lens that don't satisfy the given condition.