Pathex.Lenses.Recur (Pathex v1.3.0) View Source

see Pathex.Lenses.Recur.recur/1 documentation

Link to this section Summary

Functions

This is function which makes you lens recursive Simple example

Link to this section Functions

This is function which makes you lens recursive Simple example:

iex> import Pathex; import Pathex.Lenses.Recur
iex> # You have simple lens
iex> xlens = path(:x)

iex> # Which works like you'd expect
iex> {:ok, 1} = Pathex.view(%{x: 1}, lensx)

iex> # But then you need to take data which is nested deeply like
iex> nested = %{x: %{x: %{x: %{x: %{x: 1}}}}}

iex> # You can make this lens a recursive one
iex> recur_xlens = recur(xlens)

iex> # It'll be able to view, update and force_update all nested values
iex> {:ok, 1} = Pathex.view(nested, recur_xlens)
iex> %{x: %{x: %{x: %{x: %{x: 2}}}}} = Pathex.set!(nested, recur_xlens, 2)
iex> %{x: %{x: %{x: %{x: %{x: 2}}}}} = Pathex.force_set!(nested, recur_xlens, 2)