Optics

optics/prism

Prism is an optic used to select part of a sum type.

import "github.com/IBM/fp-go/optics/prism"

Prism is an optic used to select part of a sum type.

Functions

func AsTraversal[R ~func(func(A) HKTA) func(S) HKTS, S, A, HKTS, HKTA any]( fof func(S) HKTS, fmap func(HKTA, func(A) S) HKTS, ) func(Prism[S, A]) R

AsTraversal converts a prism to a traversal

func Compose[S, A, B any](ab Prism[A, B]) func(Prism[S, A]) Prism[S, B]

Compose composes a Prism with a Prism.

func FromPredicate[S any](pred func(S) bool) Prism[S, S]

func IMap[S any, AB ~func(A) B, BA ~func(B) A, A, B any](ab AB, ba BA) func(Prism[S, A]) Prism[S, B]

func Id[S any]() Prism[S, S]

Id returns a prism implementing the identity operation

func MakePrism[S, A any](get func(S) O.Option[A], rev func(A) S) Prism[S, A]

func Set[S, A any](a A) func(Prism[S, A]) EM.Endomorphism[S]

func Some[S, A any](soa Prism[S, O.Option[A]]) Prism[S, A]

Some returns a Prism from a Prism focused on the Some of a Option type.

Types

type Prism

Prism is an optic used to select part of a sum type.

type Prism[S, A any] interface {
	GetOption(s S) O.Option[A]
	ReverseGet(a A) S
}
Methods
  • GetOption func(s S) O.Option[A]
  • ReverseGet func(a A) S