Two disjoint lenses can be paired
Set the value viewed through the lens to a given value
A Lens[A,B] can be used as a function from A => B, or implicitly via Lens.
A Lens[A,B] can be used as a function from A => B, or implicitly via Lens.asState as a State[A,B] action
Lenses can be composed
flatMapping a lens yields a state action to avoid ambiguity
We can contravariantly map the state of a state monad through a lens
Contravariantly mapping the state of a state monad through a lens is a natural transformation
Mapping a lens yields a state action to avoid ambiguity
Modify the value viewed through the lens
Modify the value viewed through the lens, a functor full of results
modp[C] = modf[PartialApply1Of2[Tuple,C]#Flip], but is more convenient to think about
modify the state, and return a derived value as a state monadic action.
modify the portion of the state viewed through the lens and return its new value
modify the portion of the state viewed through the lens, but do not return its new value
A Lens[A,B] can be used directly as a State[A,B] that retrieves the value viewed from the state
A Lens[A,B] can be used directly as a State[A,B] that retrieves the value viewed from the state
You can apply an isomorphism to the value viewed through the lens to obtain a new lens.
Two lenses that view a value of the same type can be joined
Lenses are required to satisfy the following two laws and to be side-effect free.
All instances must satisfy 2 laws:
forall a. lens.set(a,lens(a)) = a - retention
forall a b. lens(lens.set(a,b)) = b