either

package
v1.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package either provides cross type transformations for `mo.Either`.

The functions provided by this package are not methods of `mo.Either` due to the lack of method type parameters on methods. This is part of the design decision of the Go's generics as explained here: https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#No-parameterized-methods

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FlatMapLeft

func FlatMapLeft[Lin any, R any, Lout any](f func(Lin) mo.Either[Lout, R]) func(either mo.Either[Lin, R]) mo.Either[Lout, R]

FlatMapLeft returns a new `mo.Either` wrapping the result of applying `f` to the left value of the either.

func FlatMapRight

func FlatMapRight[L any, Rin any, Rout any](f func(Rin) mo.Either[L, Rout]) func(either mo.Either[L, Rin]) mo.Either[L, Rout]

FlatMapRight returns a new `mo.Either` wrapping the result of applying `f` to the right value of the either.

func MapLeft

func MapLeft[Lin any, R any, Lout any](f func(Lin) Lout) func(either mo.Either[Lin, R]) mo.Either[Lout, R]

MapLeft returns a new `mo.Either` wrapping the result of applying `f` to the left value of the either.

func MapRight

func MapRight[L any, Rin any, Rout any](f func(Rin) Rout) func(either mo.Either[L, Rin]) mo.Either[L, Rout]

MapRight returns a new `mo.Either` wrapping the result of applying `f` to the right value of the either.

func Match

func Match[Lin any, Rin any, Lout any, Rout any](onLeft func(Lin) Lout, onRight func(Rin) Rout) func(either mo.Either[Lin, Rin]) mo.Either[Lout, Rout]

Match returns the result of applying `onLeft` to the left value of the either or `onRight` to the right value of the either.

func Pipe1

func Pipe1[A1 any, A2 any, B1 any, B2 any](
	source mo.Either[A1, A2],
	operator1 func(mo.Either[A1, A2]) mo.Either[B1, B2],
) mo.Either[B1, B2]

func Pipe10

func Pipe10[A1 any, A2 any, B1 any, B2 any, C1 any, C2 any, D1 any, D2 any, E1 any, E2 any, F1 any, F2 any, G1 any, G2 any, H1 any, H2 any, I1 any, I2 any, J1 any, J2 any, K1 any, K2 any](
	source mo.Either[A1, A2],
	operator1 func(mo.Either[A1, A2]) mo.Either[B1, B2],
	operator2 func(mo.Either[B1, B2]) mo.Either[C1, C2],
	operator3 func(mo.Either[C1, C2]) mo.Either[D1, D2],
	operator4 func(mo.Either[D1, D2]) mo.Either[E1, E2],
	operator5 func(mo.Either[E1, E2]) mo.Either[F1, F2],
	operator6 func(mo.Either[F1, F2]) mo.Either[G1, G2],
	operator7 func(mo.Either[G1, G2]) mo.Either[H1, H2],
	operator8 func(mo.Either[H1, H2]) mo.Either[I1, I2],
	operator9 func(mo.Either[I1, I2]) mo.Either[J1, J2],
	operator10 func(mo.Either[J1, J2]) mo.Either[K1, K2],
) mo.Either[K1, K2]

func Pipe2

func Pipe2[A1 any, A2 any, B1 any, B2 any, C1 any, C2 any](
	source mo.Either[A1, A2],
	operator1 func(mo.Either[A1, A2]) mo.Either[B1, B2],
	operator2 func(mo.Either[B1, B2]) mo.Either[C1, C2],
) mo.Either[C1, C2]

func Pipe3

func Pipe3[A1 any, A2 any, B1 any, B2 any, C1 any, C2 any, D1 any, D2 any](
	source mo.Either[A1, A2],
	operator1 func(mo.Either[A1, A2]) mo.Either[B1, B2],
	operator2 func(mo.Either[B1, B2]) mo.Either[C1, C2],
	operator3 func(mo.Either[C1, C2]) mo.Either[D1, D2],
) mo.Either[D1, D2]

func Pipe4

func Pipe4[A1 any, A2 any, B1 any, B2 any, C1 any, C2 any, D1 any, D2 any, E1 any, E2 any](
	source mo.Either[A1, A2],
	operator1 func(mo.Either[A1, A2]) mo.Either[B1, B2],
	operator2 func(mo.Either[B1, B2]) mo.Either[C1, C2],
	operator3 func(mo.Either[C1, C2]) mo.Either[D1, D2],
	operator4 func(mo.Either[D1, D2]) mo.Either[E1, E2],
) mo.Either[E1, E2]

func Pipe5

func Pipe5[A1 any, A2 any, B1 any, B2 any, C1 any, C2 any, D1 any, D2 any, E1 any, E2 any, F1 any, F2 any](
	source mo.Either[A1, A2],
	operator1 func(mo.Either[A1, A2]) mo.Either[B1, B2],
	operator2 func(mo.Either[B1, B2]) mo.Either[C1, C2],
	operator3 func(mo.Either[C1, C2]) mo.Either[D1, D2],
	operator4 func(mo.Either[D1, D2]) mo.Either[E1, E2],
	operator5 func(mo.Either[E1, E2]) mo.Either[F1, F2],
) mo.Either[F1, F2]

func Pipe6

func Pipe6[A1 any, A2 any, B1 any, B2 any, C1 any, C2 any, D1 any, D2 any, E1 any, E2 any, F1 any, F2 any, G1 any, G2 any](
	source mo.Either[A1, A2],
	operator1 func(mo.Either[A1, A2]) mo.Either[B1, B2],
	operator2 func(mo.Either[B1, B2]) mo.Either[C1, C2],
	operator3 func(mo.Either[C1, C2]) mo.Either[D1, D2],
	operator4 func(mo.Either[D1, D2]) mo.Either[E1, E2],
	operator5 func(mo.Either[E1, E2]) mo.Either[F1, F2],
	operator6 func(mo.Either[F1, F2]) mo.Either[G1, G2],
) mo.Either[G1, G2]

func Pipe7

func Pipe7[A1 any, A2 any, B1 any, B2 any, C1 any, C2 any, D1 any, D2 any, E1 any, E2 any, F1 any, F2 any, G1 any, G2 any, H1 any, H2 any](
	source mo.Either[A1, A2],
	operator1 func(mo.Either[A1, A2]) mo.Either[B1, B2],
	operator2 func(mo.Either[B1, B2]) mo.Either[C1, C2],
	operator3 func(mo.Either[C1, C2]) mo.Either[D1, D2],
	operator4 func(mo.Either[D1, D2]) mo.Either[E1, E2],
	operator5 func(mo.Either[E1, E2]) mo.Either[F1, F2],
	operator6 func(mo.Either[F1, F2]) mo.Either[G1, G2],
	operator7 func(mo.Either[G1, G2]) mo.Either[H1, H2],
) mo.Either[H1, H2]

func Pipe8

func Pipe8[A1 any, A2 any, B1 any, B2 any, C1 any, C2 any, D1 any, D2 any, E1 any, E2 any, F1 any, F2 any, G1 any, G2 any, H1 any, H2 any, I1 any, I2 any](
	source mo.Either[A1, A2],
	operator1 func(mo.Either[A1, A2]) mo.Either[B1, B2],
	operator2 func(mo.Either[B1, B2]) mo.Either[C1, C2],
	operator3 func(mo.Either[C1, C2]) mo.Either[D1, D2],
	operator4 func(mo.Either[D1, D2]) mo.Either[E1, E2],
	operator5 func(mo.Either[E1, E2]) mo.Either[F1, F2],
	operator6 func(mo.Either[F1, F2]) mo.Either[G1, G2],
	operator7 func(mo.Either[G1, G2]) mo.Either[H1, H2],
	operator8 func(mo.Either[H1, H2]) mo.Either[I1, I2],
) mo.Either[I1, I2]

func Pipe9

func Pipe9[A1 any, A2 any, B1 any, B2 any, C1 any, C2 any, D1 any, D2 any, E1 any, E2 any, F1 any, F2 any, G1 any, G2 any, H1 any, H2 any, I1 any, I2 any, J1 any, J2 any](
	source mo.Either[A1, A2],
	operator1 func(mo.Either[A1, A2]) mo.Either[B1, B2],
	operator2 func(mo.Either[B1, B2]) mo.Either[C1, C2],
	operator3 func(mo.Either[C1, C2]) mo.Either[D1, D2],
	operator4 func(mo.Either[D1, D2]) mo.Either[E1, E2],
	operator5 func(mo.Either[E1, E2]) mo.Either[F1, F2],
	operator6 func(mo.Either[F1, F2]) mo.Either[G1, G2],
	operator7 func(mo.Either[G1, G2]) mo.Either[H1, H2],
	operator8 func(mo.Either[H1, H2]) mo.Either[I1, I2],
	operator9 func(mo.Either[I1, I2]) mo.Either[J1, J2],
) mo.Either[J1, J2]

func Swap

func Swap[I any, O any]() func(either mo.Either[I, O]) mo.Either[O, I]

Swap returns the left value in Right and vice versa.

func TestPipeTypeTransformations

func TestPipeTypeTransformations(t *testing.T)

Types

This section is empty.