A Fold can be seen as a Getter with many targets or a weaker PTraversal which cannot modify its target.
A Getter can be seen as a glorified get method between a type S and a type A.
Iso is a type alias for PIso where S
= A
and T
= B
:
Iso is a type alias for PIso where S
= A
and T
= B
:
type Iso[S, A] = PIso[S, S, A, A]
An Iso defines an isomorphism between a type S and A:
get --------------------> S A <-------------------- reverseGet
A PIso allows to lift a function f: A => B
to S => T
and a function g: T => S
to B => A
g S T S <-------- T | ↑ | ↑ | | | | get | | reverseGet reverse.reverseGet | | reverse.get | | | | ↓ f | ↓ | A --------> B A B
A PIso is also a valid Getter, Fold, PLens, PPrism, POptional, PTraversal and PSetter
the source of a PIso
the modified source of a PIso
the target of a PIso
the modified target of a PIso
A PLens can be seen as a pair of functions:
A PLens can be seen as a pair of functions:
get: S => A
i.e. from an S
, we can extract an A
set: (B, S) => T
i.e. if we replace an A
by a B
in an S
, we obtain a T
A PLens could also be defined as a weaker PIso where set requires an additional parameter than reverseGet.
PLens stands for Polymorphic Lens as it set and modify methods change
a type A
to B
and S
to T
.
Lens is a type alias for PLens restricted to monomorphic updates:
type Lens[S, A] = PLens[S, S, A, A]
A PLens is also a valid Getter, Fold, POptional, PTraversal and PSetter
Typically a PLens or Lens can be defined between a Product (e.g. case class, tuple, HList) and one of it is component.
the source of a PLens
the modified source of a PLens
the target of a PLens
the modified target of a PLens
A POptional can be seen as a pair of functions:
A POptional can be seen as a pair of functions:
getOrModify: S => T \/ A
set : (B, S) => T
A POptional could also be defined as a weaker PLens and weaker PPrism
POptional stands for Polymorphic Optional as it set and modify methods change
a type A
to B
and S
to T
.
Optional is a type alias for POptional restricted to monomorphic updates:
type Optional[S, A] = POptional[S, S, A, A]
the source of a POptional
the modified source of a POptional
the target of a POptional
the modified target of a POptional
A PPrism can be seen as a pair of functions:
A PPrism can be seen as a pair of functions:
getOrModify: S => T \/ A
reverseGet : B => T
A PPrism could also be defined as a weaker PIso where get can fail.
Typically a PPrism or Prism encodes the relation between a Sum or CoProduct type (e.g. sealed trait) and one of it is element.
PPrism stands for Polymorphic Prism as it set and modify methods change
a type A
to B
and S
to T
.
Prism is a type alias for PPrism where the type of target cannot be modified:
type Prism[S, A] = PPrism[S, S, A, A]
A PPrism is also a valid Fold, POptional, PTraversal and PSetter
the source of a PPrism
the modified source of a PPrism
the target of a PPrism
the modified target of a PPrism
A PSetter is a generalisation of Functor map:
A PSetter is a generalisation of Functor map:
map: (A => B) => F[A] => F[B]
modify: (A => B) => S => T
PSetter stands for Polymorphic Setter as it set and modify methods change
a type A
to B
and S
to T
.
Setter is a type alias for PSetter restricted to monomorphic updates:
type Setter[S, A] = PSetter[S, S, A, A]
PTraversal, POptional, PPrism, PLens and PIso are valid PSetter
the source of a PSetter
the modified source of a PSetter
the target of a PSetter
the modified target of a PSetter
A PTraversal can be seen as a POptional generalised to 0 to n targets where n can be infinite.
A PTraversal can be seen as a POptional generalised to 0 to n targets where n can be infinite.
PTraversal stands for Polymorphic Traversal as it set and modify methods change
a type A
to B
and S
to T
.
Traversal is a type alias for PTraversal restricted to monomorphic updates:
type Traversal[S, A] = PTraversal[S, S, A, A]
the source of a PTraversal
the modified source of a PTraversal
the target of a PTraversal
the modified target of a PTraversal