lens package:optics-core
Build a lens from a getter and a setter, which must respect the
well-formedness laws.
If you want to build a
Lens from the van Laarhoven
representation, use
lensVL.
A
Lens is a generalised or first-class field.
If we have a value
s :: S, and a
l :: Lens' S
A, we can
get the "field value" of type
A using
view l s. We can also
update (or
put or
set) the value using
over (or
set).
For example, given the following definitions:
>>> data Human = Human { _name :: String, _location :: String } deriving Show
>>> let human = Human "Bob" "London"
we can make a
Lens for
_name field:
>>> let name = lens _name $ \s x -> s { _name = x }
which we can use as a
Getter:
>>> view name human
"Bob"
or a
Setter:
>>> set name "Robert" human
Human {_name = "Robert", _location = "London"}
Type synonym for a type-modifying lens.
Build a lens from the van Laarhoven representation.
Type synonym for a type-preserving lens.
Type synonym for a type-modifying van Laarhoven lens.
Type synonym for a type-preserving van Laarhoven lens.
An
IxLens is an indexed version of a
Lens. See the
"Indexed optics" section of the overview documentation in the
Optics module of the main
optics package for more
details on indexed optics.
Type synonym for a type-modifying indexed lens.
Type synonym for a type-preserving indexed lens.
Type synonym for a type-modifying van Laarhoven indexed lens.
Type synonym for a type-preserving van Laarhoven indexed lens.
Build an indexed lens from a getter and a setter.
If you want to build an
IxLens from the van Laarhoven
representation, use
ilensVL.
Build an indexed lens from the van Laarhoven representation.
Convert an indexed lens to its van Laarhoven representation.
Work with an indexed lens in the van Laarhoven representation.
Convert a lens to the van Laarhoven representation.
Work with a lens as a getter and a setter.
withLens (lens f g) k ≡ k f g
Work with a lens in the van Laarhoven representation.
Type synonym for a type-modifying reversed lens.
Type synonym for a type-preserving reversed lens.