Documentation
¶
Overview ¶
Lens is an optic used to zoom inside a product.
Index ¶
- func Compose[S, A, B any](ab Lens[A, B]) func(Lens[S, A]) Lens[S, B]
- func ComposeOption[S, B, A any](defaultA A) func(ab Lens[A, B]) func(Lens[S, O.Option[A]]) Lens[S, O.Option[B]]
- func ComposeOptions[S, B, A any](defaultA A) func(ab Lens[A, O.Option[B]]) func(Lens[S, O.Option[A]]) Lens[S, O.Option[B]]
- func ComposeRef[S, A, B any](ab Lens[A, B]) func(Lens[*S, A]) Lens[*S, B]
- func FromNullableProp[S, A any](isNullable func(A) O.Option[A], defaultValue A) func(sa Lens[S, A]) Lens[S, A]
- func FromNullablePropRef[S, A any](isNullable func(A) O.Option[A], defaultValue A) func(sa Lens[*S, A]) Lens[*S, A]
- func FromOption[S, A any](defaultValue A) func(sa Lens[S, O.Option[A]]) Lens[S, A]
- func FromOptionRef[S, A any](defaultValue A) func(sa Lens[*S, O.Option[A]]) Lens[*S, A]
- func FromPredicate[S, A any](pred func(A) bool, nilValue A) func(sa Lens[S, A]) Lens[S, O.Option[A]]
- func FromPredicateRef[S, A any](pred func(A) bool, nilValue A) func(sa Lens[*S, A]) Lens[*S, O.Option[A]]
- func IMap[E any, AB ~func(A) B, BA ~func(B) A, A, B any](ab AB, ba BA) func(Lens[E, A]) Lens[E, B]
- func Modify[S any, FCT ~func(A) A, A any](f FCT) func(Lens[S, A]) EM.Endomorphism[S]
- type Lens
- func FromNillable[S, A any](sa Lens[S, *A]) Lens[S, O.Option[*A]]
- func FromNillableRef[S, A any](sa Lens[*S, *A]) Lens[*S, O.Option[*A]]
- func Id[S any]() Lens[S, S]
- func IdRef[S any]() Lens[*S, *S]
- func MakeLens[GET ~func(S) A, SET ~func(S, A) S, S, A any](get GET, set SET) Lens[S, A]
- func MakeLensCurried[GET ~func(S) A, SET ~func(A) EM.Endomorphism[S], S, A any](get GET, set SET) Lens[S, A]
- func MakeLensRef[GET ~func(*S) A, SET func(*S, A) *S, S, A any](get GET, set SET) Lens[*S, A]
- func MakeLensRefCurried[S, A any](get func(*S) A, set func(A) EM.Endomorphism[*S]) Lens[*S, A]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComposeOption ¶
func ComposeOption[S, B, A any](defaultA A) func(ab Lens[A, B]) func(Lens[S, O.Option[A]]) Lens[S, O.Option[B]]
ComposeOption combines a `Lens` that returns an optional value with a `Lens` that returns a definite value the getter returns an `Option[B]` because the container `A` could already be an option if the setter is invoked with `Some[B]` then the value of `B` will be set, potentially on a default value of `A` if `A` did not exist if the setter is invoked with `None[B]` then the container `A` is reset to `None[A]` because this is the only way to remove `B`
func ComposeOptions ¶
func ComposeOptions[S, B, A any](defaultA A) func(ab Lens[A, O.Option[B]]) func(Lens[S, O.Option[A]]) Lens[S, O.Option[B]]
ComposeOptions combines a `Lens` that returns an optional value with a `Lens` that returns another optional value the getter returns `None[B]` if either `A` or `B` is `None` if the setter is called with `Some[B]` and `A` exists, 'A' is updated with `B` if the setter is called with `Some[B]` and `A` does not exist, the default of 'A' is updated with `B` if the setter is called with `None[B]` and `A` does not exist this is the identity operation on 'S' if the setter is called with `None[B]` and `A` does exist, 'B' is removed from 'A'
func ComposeRef ¶
Compose combines two lenses and allows to narrow down the focus to a sub-lens
func FromNullableProp ¶
func FromNullableProp[S, A any](isNullable func(A) O.Option[A], defaultValue A) func(sa Lens[S, A]) Lens[S, A]
FromNullableProp returns a `Lens` from a property that may be optional. The getter returns a default value for these items
func FromNullablePropRef ¶
func FromNullablePropRef[S, A any](isNullable func(A) O.Option[A], defaultValue A) func(sa Lens[*S, A]) Lens[*S, A]
FromNullablePropRef returns a `Lens` from a property that may be optional. The getter returns a default value for these items
func FromOption ¶
FromFromOption returns a `Lens` from an option property. The getter returns a default value the setter will always set the some option
func FromOptionRef ¶
FromFromOptionRef returns a `Lens` from an option property. The getter returns a default value the setter will always set the some option
func FromPredicate ¶
func FromPredicate[S, A any](pred func(A) bool, nilValue A) func(sa Lens[S, A]) Lens[S, O.Option[A]]
FromPredicate returns a `Lens` for a property accessibly as a getter and setter that can be optional if the optional value is set then the nil value will be set instead
func FromPredicateRef ¶
func FromPredicateRef[S, A any](pred func(A) bool, nilValue A) func(sa Lens[*S, A]) Lens[*S, O.Option[A]]
FromPredicateRef returns a `Lens` for a property accessibly as a getter and setter that can be optional if the optional value is set then the nil value will be set instead
Types ¶
type Lens ¶
type Lens[S, A any] struct { Get func(s S) A Set func(a A) EM.Endomorphism[S] }
Lens is a reference to a subpart of a data type
func FromNillable ¶
FromPredicate returns a `Lens` for a property accessibly as a getter and setter that can be optional if the optional value is set then the `nil` value will be set instead
func FromNillableRef ¶
FromNillableRef returns a `Lens` for a property accessibly as a getter and setter that can be optional if the optional value is set then the `nil` value will be set instead
func MakeLens ¶
MakeLens creates a Lens 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 `MakeLensRef` and for other kinds of data structures that are copied by reference make sure the setter creates the copy.
func MakeLensCurried ¶
func MakeLensCurried[GET ~func(S) A, SET ~func(A) EM.Endomorphism[S], S, A any](get GET, set SET) Lens[S, A]
MakeLensCurried creates a Lens 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 `MakeLensRef` and for other kinds of data structures that are copied by reference make sure the setter creates the copy.
func MakeLensRef ¶
MakeLensRef creates a Lens 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
Such a Lens assumes that property A of S always exists
func MakeLensRefCurried ¶
func MakeLensRefCurried[S, A any](get func(*S) A, set func(A) EM.Endomorphism[*S]) Lens[*S, A]
MakeLensRefCurried creates a Lens 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
Such a Lens assumes that property A of S always exists