Documentation
¶
Overview ¶
Optional is an optic used to zoom inside a product. Unlike the `Lens`, the element that the `Optional` focuses on may not exist.
Index ¶
- func Compose[S, A, B any](ab Optional[A, B]) func(Optional[S, A]) Optional[S, B]
- func ComposeRef[S, A, B any](ab Optional[A, B]) func(Optional[*S, A]) Optional[*S, B]
- func FromPredicate[S, A any](pred func(A) bool) func(func(S) A, func(S, A) S) Optional[S, A]
- func FromPredicateRef[S, A any](pred func(A) bool) func(func(*S) A, func(*S, A) *S) Optional[*S, A]
- func IChain[S, A, B any](ab func(A) O.Option[B], ba func(B) O.Option[A]) func(Optional[S, A]) Optional[S, B]
- func IChainAny[S, A any]() func(Optional[S, any]) Optional[S, A]
- func IMap[S, A, B any](ab func(A) B, ba func(B) A) func(Optional[S, A]) Optional[S, B]
- func ModifyOption[S, A any](f func(A) A) func(Optional[S, A]) func(S) O.Option[S]
- func SetOption[S, A any](a A) func(Optional[S, A]) func(S) O.Option[S]
- type Optional
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComposeRef ¶
ComposeRef combines two Optional and allows to narrow down the focus to a sub-Optional
func FromPredicate ¶
FromPredicate creates an optional from getter and setter functions. It checks for optional values and the correct update procedure
func FromPredicateRef ¶
FromPredicate creates an optional from getter and setter functions. It checks for optional values and the correct update procedure
func IChain ¶
func IChain[S, A, B any](ab func(A) O.Option[B], ba func(B) O.Option[A]) func(Optional[S, A]) Optional[S, B]
IChain implements a bidirectional mapping of the transform if the transform can produce optionals (e.g. in case of type mappings)
func ModifyOption ¶
Types ¶
type Optional ¶
type Optional[S, A any] struct { GetOption func(s S) O.Option[A] Set func(a A) EM.Endomorphism[S] }
Optional is an optional reference to a subpart of a data type
func MakeOptional ¶
MakeOptional creates an Optional based on a getter and a setter function. Make sure that the setter creates a (shallow) copy of the data. This happens automatically if the data is passed by value. For pointers consider to use `MakeOptionalRef` and for other kinds of data structures that are copied by reference make sure the setter creates the copy.
func MakeOptionalRef ¶
MakeOptionalRef creates an Optional based on a getter and a setter function. The setter passed in does not have to create a shallow copy, the implementation wraps the setter into one that copies the pointer before modifying it