generic

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ap

func Ap[
	GRB ~func(context.Context) GIOB,
	GRAB ~func(context.Context) GIOAB,
	GRA ~func(context.Context) GIOA,

	GIOA ~func() E.Either[error, A],
	GIOB ~func() E.Either[error, B],
	GIOAB ~func() E.Either[error, func(A) B],

	A, B any](fa GRA) func(GRAB) GRB

func Ask

func Ask[
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, context.Context],

]() GRA

func Asks

func Asks[
	GRA ~func(context.Context) GIOA,
	GRB ~func(context.Context) A,
	GIOA ~func() E.Either[error, A],

	A any](r GRB) GRA

func Chain

func Chain[
	GRA ~func(context.Context) GIOA,
	GRB ~func(context.Context) GIOB,

	GIOA ~func() E.Either[error, A],
	GIOB ~func() E.Either[error, B],

	A, B any](f func(A) GRB) func(GRA) GRB

func ChainEitherK

func ChainEitherK[
	GRA ~func(context.Context) GIOA,
	GRB ~func(context.Context) GIOB,
	GIOA ~func() E.Either[error, A],

	GIOB ~func() E.Either[error, B],

	A, B any](f func(A) E.Either[error, B]) func(ma GRA) GRB

func ChainFirst

func ChainFirst[
	GRA ~func(context.Context) GIOA,
	GRB ~func(context.Context) GIOB,

	GIOA ~func() E.Either[error, A],
	GIOB ~func() E.Either[error, B],

	A, B any](f func(A) GRB) func(GRA) GRA

func ChainFirstEitherK

func ChainFirstEitherK[
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, A],

	A, B any](f func(A) E.Either[error, B]) func(ma GRA) GRA

func ChainFirstIOK

func ChainFirstIOK[
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, A],

	GIO ~func() B,

	A, B any](f func(A) GIO) func(ma GRA) GRA

func ChainIOEitherK

func ChainIOEitherK[
	GRA ~func(context.Context) GIOA,
	GRB ~func(context.Context) GIOB,
	GIOA ~func() E.Either[error, A],

	GIOB ~func() E.Either[error, B],

	A, B any](f func(A) GIOB) func(ma GRA) GRB

func ChainIOK

func ChainIOK[
	GRB ~func(context.Context) GIOB,
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, A],

	GIOB ~func() E.Either[error, B],

	GIO ~func() B,

	A, B any](f func(A) GIO) func(ma GRA) GRB

func ChainOptionK

func ChainOptionK[
	GRA ~func(context.Context) GIOA,
	GRB ~func(context.Context) GIOB,

	GIOB ~func() E.Either[error, B],

	GIOA ~func() E.Either[error, A],

	A, B any](onNone func() error) func(func(A) O.Option[B]) func(GRA) GRB

func Defer

func Defer[
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, A],

	A any](gen func() GRA) GRA

Defer creates an IO by creating a brand new IO via a generator function, each time

func Delay

func Delay[
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, A],

	A any](delay time.Duration) func(ma GRA) GRA

Delay creates an operation that passes in the value after some delay

func Eitherize0

func Eitherize0[GRA ~func(context.Context) GIOA, F ~func(context.Context) (R, error), GIOA ~func() E.Either[error, R], R any](f F) func() GRA

Eitherize0 converts a function with 0 parameters returning a tuple into a function with 0 parameters returning a [GRA] The inverse function is [Uneitherize0]

func Eitherize1

func Eitherize1[GRA ~func(context.Context) GIOA, F ~func(context.Context, T0) (R, error), GIOA ~func() E.Either[error, R], T0, R any](f F) func(T0) GRA

Eitherize1 converts a function with 1 parameters returning a tuple into a function with 1 parameters returning a [GRA] The inverse function is [Uneitherize1]

func Eitherize10

func Eitherize10[GRA ~func(context.Context) GIOA, F ~func(context.Context, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) GRA

Eitherize10 converts a function with 10 parameters returning a tuple into a function with 10 parameters returning a [GRA] The inverse function is [Uneitherize10]

func Eitherize2

func Eitherize2[GRA ~func(context.Context) GIOA, F ~func(context.Context, T0, T1) (R, error), GIOA ~func() E.Either[error, R], T0, T1, R any](f F) func(T0, T1) GRA

Eitherize2 converts a function with 2 parameters returning a tuple into a function with 2 parameters returning a [GRA] The inverse function is [Uneitherize2]

func Eitherize3

func Eitherize3[GRA ~func(context.Context) GIOA, F ~func(context.Context, T0, T1, T2) (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, R any](f F) func(T0, T1, T2) GRA

Eitherize3 converts a function with 3 parameters returning a tuple into a function with 3 parameters returning a [GRA] The inverse function is [Uneitherize3]

func Eitherize4

func Eitherize4[GRA ~func(context.Context) GIOA, F ~func(context.Context, T0, T1, T2, T3) (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, R any](f F) func(T0, T1, T2, T3) GRA

Eitherize4 converts a function with 4 parameters returning a tuple into a function with 4 parameters returning a [GRA] The inverse function is [Uneitherize4]

func Eitherize5

func Eitherize5[GRA ~func(context.Context) GIOA, F ~func(context.Context, T0, T1, T2, T3, T4) (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, R any](f F) func(T0, T1, T2, T3, T4) GRA

Eitherize5 converts a function with 5 parameters returning a tuple into a function with 5 parameters returning a [GRA] The inverse function is [Uneitherize5]

func Eitherize6

func Eitherize6[GRA ~func(context.Context) GIOA, F ~func(context.Context, T0, T1, T2, T3, T4, T5) (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, T5, R any](f F) func(T0, T1, T2, T3, T4, T5) GRA

Eitherize6 converts a function with 6 parameters returning a tuple into a function with 6 parameters returning a [GRA] The inverse function is [Uneitherize6]

func Eitherize7

func Eitherize7[GRA ~func(context.Context) GIOA, F ~func(context.Context, T0, T1, T2, T3, T4, T5, T6) (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, T5, T6, R any](f F) func(T0, T1, T2, T3, T4, T5, T6) GRA

Eitherize7 converts a function with 7 parameters returning a tuple into a function with 7 parameters returning a [GRA] The inverse function is [Uneitherize7]

func Eitherize8

func Eitherize8[GRA ~func(context.Context) GIOA, F ~func(context.Context, T0, T1, T2, T3, T4, T5, T6, T7) (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, T5, T6, T7, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) GRA

Eitherize8 converts a function with 8 parameters returning a tuple into a function with 8 parameters returning a [GRA] The inverse function is [Uneitherize8]

func Eitherize9

func Eitherize9[GRA ~func(context.Context) GIOA, F ~func(context.Context, T0, T1, T2, T3, T4, T5, T6, T7, T8) (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, T5, T6, T7, T8, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8) GRA

Eitherize9 converts a function with 9 parameters returning a tuple into a function with 9 parameters returning a [GRA] The inverse function is [Uneitherize9]

func Eq

func Eq[GRA ~func(context.Context) GIOA, GIOA ~func() E.Either[error, A], A any](eq EQ.Eq[E.Either[error, A]]) func(context.Context) EQ.Eq[GRA]

Eq implements the equals predicate for values contained in the IOEither monad

func Fold

func Fold[
	GRB ~func(context.Context) GIOB,
	GRA ~func(context.Context) GIOA,

	GIOA ~func() E.Either[error, A],
	GIOB ~func() B,

	A, B any](onLeft func(error) GRB, onRight func(A) GRB) func(GRA) GRB

func FromEither

func FromEither[
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, A],
	A any](e E.Either[error, A]) GRA

func FromIO

func FromIO[
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, A],

	GIOB ~func() A,

	A any](t GIOB) GRA

func FromIOEither

func FromIOEither[
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, A],

	A any](t GIOA) GRA

func FromPredicate

func FromPredicate[
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, A],

	A any](pred func(A) bool, onFalse func(A) error) func(A) GRA

func FromReader

func FromReader[
	GRA ~func(context.Context) GIOA,
	GR ~func(context.Context) A,
	GIOA ~func() E.Either[error, A],
	A any](r GR) GRA

func GetOrElse

func GetOrElse[
	GRB ~func(context.Context) GIOB,
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, A],

	GIOB ~func() A,

	A any](onLeft func(error) GRB) func(GRA) GRB

func Left

func Left[
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, A],
	A any](l error) GRA

func LeftReader

func LeftReader[
	GRA ~func(context.Context) GIOA,
	GR ~func(context.Context) error,
	GIOA ~func() E.Either[error, A],
	A any](l GR) GRA

func Map

func Map[
	GRA ~func(context.Context) GIOA,
	GRB ~func(context.Context) GIOB,

	GIOA ~func() E.Either[error, A],
	GIOB ~func() E.Either[error, B],

	A, B any](f func(A) B) func(GRA) GRB

func MonadAp

func MonadAp[
	GRB ~func(context.Context) GIOB,
	GRA ~func(context.Context) GIOA,
	GRAB ~func(context.Context) GIOAB,

	GIOA ~func() E.Either[error, A],
	GIOB ~func() E.Either[error, B],
	GIOAB ~func() E.Either[error, func(A) B],

	A, B any](fab GRAB, fa GRA) GRB

MonadAp implements the `Ap` function for a reader with context. It creates a sub-context that will be canceled if any of the input operations errors out or

func MonadChain

func MonadChain[
	GRA ~func(context.Context) GIOA,
	GRB ~func(context.Context) GIOB,

	GIOA ~func() E.Either[error, A],
	GIOB ~func() E.Either[error, B],

	A, B any](ma GRA, f func(A) GRB) GRB

func MonadChainEitherK

func MonadChainEitherK[
	GRA ~func(context.Context) GIOA,
	GRB ~func(context.Context) GIOB,
	GIOA ~func() E.Either[error, A],

	GIOB ~func() E.Either[error, B],

	A, B any](ma GRA, f func(A) E.Either[error, B]) GRB

func MonadChainFirst

func MonadChainFirst[
	GRA ~func(context.Context) GIOA,
	GRB ~func(context.Context) GIOB,

	GIOA ~func() E.Either[error, A],
	GIOB ~func() E.Either[error, B],

	A, B any](ma GRA, f func(A) GRB) GRA

func MonadChainFirstEitherK

func MonadChainFirstEitherK[
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, A],

	A, B any](ma GRA, f func(A) E.Either[error, B]) GRA

func MonadChainFirstIOK

func MonadChainFirstIOK[
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, A],

	GIO ~func() B,

	A, B any](ma GRA, f func(A) GIO) GRA

func MonadChainIOK

func MonadChainIOK[
	GRB ~func(context.Context) GIOB,
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, A],

	GIOB ~func() E.Either[error, B],

	GIO ~func() B,

	A, B any](ma GRA, f func(A) GIO) GRB

func MonadMap

func MonadMap[
	GRA ~func(context.Context) GIOA,
	GRB ~func(context.Context) GIOB,

	GIOA ~func() E.Either[error, A],
	GIOB ~func() E.Either[error, B],

	A, B any](fa GRA, f func(A) B) GRB

func Never

func Never[
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, A],

	A any]() GRA

Never returns a 'ReaderIOEither' that never returns, except if its context gets canceled

func Of

func Of[
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, A],

	A any](a A) GRA

func OrElse

func OrElse[
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, A],

	A any](onLeft func(error) GRA) func(GRA) GRA

func OrLeft

func OrLeft[
	GRA ~func(context.Context) GIOA,
	GRB ~func(context.Context) GIOB,
	GIOA ~func() E.Either[error, A],

	GIOB ~func() error,

	A any](onLeft func(error) GRB) func(GRA) GRA
func Right[
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, A],
	A any](r A) GRA

func RightReader

func RightReader[
	GRA ~func(context.Context) GIOA,
	GR ~func(context.Context) A,
	GIOA ~func() E.Either[error, A],
	A any](r GR) GRA

func SequenceArray

func SequenceArray[
	AS ~[]A,
	GAS ~[]GRA,
	GRAS ~func(context.Context) GIOAS,
	GRA ~func(context.Context) GIOA,
	GIOAS ~func() E.Either[error, AS],
	GIOA ~func() E.Either[error, A],
	A any](ma GAS) GRAS

SequenceArray converts a homogeneous sequence of either into an either of sequence

func SequenceRecord

func SequenceRecord[K comparable,
	AS ~map[K]A,
	GAS ~map[K]GRA,
	GRAS ~func(context.Context) GIOAS,
	GRA ~func(context.Context) GIOA,
	GIOAS ~func() E.Either[error, AS],
	GIOA ~func() E.Either[error, A],
	A any](ma GAS) GRAS

SequenceRecord converts a homogeneous sequence of either into an either of sequence

func SequenceT1

func SequenceT1[
	GRT ~func(context.Context) GIOT,
	GRA ~func(context.Context) GIOA,

	GIOA ~func() E.Either[error, A],
	GIOT ~func() E.Either[error, T.Tuple1[A]],

	A any](a GRA) GRT

func SequenceT2

func SequenceT2[
	GRT ~func(context.Context) GIOT,
	GRA ~func(context.Context) GIOA,
	GRB ~func(context.Context) GIOB,

	GIOA ~func() E.Either[error, A],
	GIOB ~func() E.Either[error, B],
	GIOT ~func() E.Either[error, T.Tuple2[A, B]],

	A, B any](a GRA, b GRB) GRT

func SequenceT3

func SequenceT3[
	GRT ~func(context.Context) GIOT,
	GRA ~func(context.Context) GIOA,
	GRB ~func(context.Context) GIOB,
	GRC ~func(context.Context) GIOC,

	GIOA ~func() E.Either[error, A],
	GIOB ~func() E.Either[error, B],
	GIOC ~func() E.Either[error, C],
	GIOT ~func() E.Either[error, T.Tuple3[A, B, C]],

	A, B, C any](a GRA, b GRB, c GRC) GRT

func SequenceT4

func SequenceT4[
	GRT ~func(context.Context) GIOT,
	GRA ~func(context.Context) GIOA,
	GRB ~func(context.Context) GIOB,
	GRC ~func(context.Context) GIOC,
	GRD ~func(context.Context) GIOD,

	GIOA ~func() E.Either[error, A],
	GIOB ~func() E.Either[error, B],
	GIOC ~func() E.Either[error, C],
	GIOD ~func() E.Either[error, D],
	GIOT ~func() E.Either[error, T.Tuple4[A, B, C, D]],

	A, B, C, D any](a GRA, b GRB, c GRC, d GRD) GRT

func Timer

func Timer[
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, time.Time],

](delay time.Duration) GRA

Timer will return the current time after an initial delay

func TraverseArray

func TraverseArray[
	AS ~[]A,
	GRBS ~func(context.Context) GIOBS,
	GRB ~func(context.Context) GIOB,
	GIOBS ~func() E.Either[error, BS],
	GIOB ~func() E.Either[error, B],
	BS ~[]B,
	A, B any](f func(A) GRB) func(AS) GRBS

TraverseArray transforms an array

func TraverseRecord

func TraverseRecord[K comparable,
	AS ~map[K]A,
	GRBS ~func(context.Context) GIOBS,
	GRB ~func(context.Context) GIOB,
	GIOBS ~func() E.Either[error, BS],
	GIOB ~func() E.Either[error, B],
	BS ~map[K]B,

	A, B any](f func(A) GRB) func(AS) GRBS

TraverseRecord transforms a record

func TryCatch

func TryCatch[
	GRA ~func(context.Context) GIOA,
	GIOA ~func() E.Either[error, A],

	A any](f func(context.Context) func() (A, error)) GRA

TryCatch wraps a reader returning a tuple as an error into ReaderIOEither

func WithContext

func WithContext[GRA ~func(context.Context) GIOA, GIOA ~func() E.Either[error, A], A any](ma GRA) GRA

withContext wraps an existing ReaderIOEither and performs a context check for cancellation before delegating

func WithResource

func WithResource[
	GRA ~func(context.Context) GIOA,
	GRR ~func(context.Context) GIOR,
	GRANY ~func(context.Context) GIOANY,
	GIOR ~func() E.Either[error, R],
	GIOA ~func() E.Either[error, A],
	GIOANY ~func() E.Either[error, ANY],
	R, A, ANY any](onCreate GRR, onRelease func(R) GRANY) func(func(R) GRA) GRA

WithResource constructs a function that creates a resource, then operates on it and then releases the resource

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL