Optics

optics/iso

Iso is an optic which converts elements of type S into elements of type A without loss.

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

Iso is an optic which converts elements of type S into elements of type A without loss.

Functions

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

Compose combines an ISO with another ISO

func From[S, A any](a A) func(Iso[S, A]) S

To unwraps the value

func IMap[S, A, B any](ab func(A) B, ba func(B) A) func(Iso[S, A]) Iso[S, B]

IMap implements a bidirectional mapping of the transform

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

Id returns an iso implementing the identity operation

func MakeIso[S, A any](get func(S) A, reverse func(A) S) Iso[S, A]

func Modify[S any, FCT ~func(A) A, A any](f FCT) func(Iso[S, A]) EM.Endomorphism[S]

Modify applies a transformation

func Reverse[S, A any](sa Iso[S, A]) Iso[A, S]

Reverse changes the order of parameters for an iso

func To[A, S any](s S) func(Iso[S, A]) A

From wraps the value

func Unwrap[A, S any](s S) func(Iso[S, A]) A

Wrap wraps the value

func Wrap[S, A any](a A) func(Iso[S, A]) S

Unwrap unwraps the value

Types

type Iso

type Iso[S, A any] struct {
	Get        func(s S) A
	ReverseGet func(a A) S
}
Fields
  • Get func(s S) A
  • ReverseGet func(a A) S