t

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: MIT Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compose

func Compose[T, U, V any](fn1 func(T) U, fn2 func(U) V) func(T) V

func Empty

func Empty[T any]() (t T)

func ErrMapUp

func ErrMapUp[E error](fn func(error) E) func(error) error

func Id

func Id[T any](t T) T

The identity map

func If

func If[Out, T any](r Option[T], someFn func(T) Out, noneFn func() Out) Out

func Match

func Match[Out, T any](r Result[T], okFn func(T) Out, errFn func(error) Out) Out

func Return

func Return[In any, T any](t T) func(In) T

Return the given value, given any input of type In

func Return0

func Return0[T any](t T) func() T

Return the given value, given any input of type In

Types

type ApplyToResult

type ApplyToResult[Out, T any] struct {
	// contains filtered or unexported fields
}

func Chain

func Chain[Out, T any](result Result[T]) ApplyToResult[Out, T]

func (ApplyToResult[O, T]) AndThen

func (a ApplyToResult[O, T]) AndThen(fn func(T) Result[O]) Result[O]

func (ApplyToResult[O, T]) Map

func (a ApplyToResult[O, T]) Map(fn func(T) O) Result[O]

type ApplyToResult10

type ApplyToResult10[O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, T any] struct {
	// contains filtered or unexported fields
}

func Chain10

func Chain10[Out10, Out9, Out8, Out7, Out6, Out5, Out4, Out3, Out2, Out1, T any](result Result[T]) ApplyToResult10[Out1, Out2, Out3, Out4, Out5, Out6, Out7, Out8, Out9, Out10, T]

func (ApplyToResult10[O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, T]) AndThen

func (a ApplyToResult10[O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, T]) AndThen(fn func(T) Result[O1]) ApplyToResult9[O10, O9, O8, O7, O6, O5, O4, O3, O2, O1]

func (ApplyToResult10[O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, T]) Map

func (a ApplyToResult10[O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, T]) Map(fn func(T) O1) ApplyToResult9[O10, O9, O8, O7, O6, O5, O4, O3, O2, O1]

type ApplyToResult2

type ApplyToResult2[O1, O2, T any] struct {
	// contains filtered or unexported fields
}

func Chain2

func Chain2[Out2, Out1, T any](result Result[T]) ApplyToResult2[Out1, Out2, T]

func (ApplyToResult2[O1, O2, T]) AndThen

func (a ApplyToResult2[O1, O2, T]) AndThen(fn func(T) Result[O1]) ApplyToResult[O2, O1]

func (ApplyToResult2[O1, O2, T]) Map

func (a ApplyToResult2[O1, O2, T]) Map(fn func(T) O1) ApplyToResult[O2, O1]

type ApplyToResult3

type ApplyToResult3[O1, O2, O3, T any] struct {
	// contains filtered or unexported fields
}

func Chain3

func Chain3[Out3, Out2, Out1, T any](result Result[T]) ApplyToResult3[Out1, Out2, Out3, T]

func (ApplyToResult3[O1, O2, O3, T]) AndThen

func (a ApplyToResult3[O1, O2, O3, T]) AndThen(fn func(T) Result[O1]) ApplyToResult2[O3, O2, O1]

func (ApplyToResult3[O1, O2, O3, T]) Map

func (a ApplyToResult3[O1, O2, O3, T]) Map(fn func(T) O1) ApplyToResult2[O3, O2, O1]

type ApplyToResult4

type ApplyToResult4[O1, O2, O3, O4, T any] struct {
	// contains filtered or unexported fields
}

func Chain4

func Chain4[Out4, Out3, Out2, Out1, T any](result Result[T]) ApplyToResult4[Out1, Out2, Out3, Out4, T]

func (ApplyToResult4[O1, O2, O3, O4, T]) AndThen

func (a ApplyToResult4[O1, O2, O3, O4, T]) AndThen(fn func(T) Result[O1]) ApplyToResult3[O4, O3, O2, O1]

func (ApplyToResult4[O1, O2, O3, O4, T]) Map

func (a ApplyToResult4[O1, O2, O3, O4, T]) Map(fn func(T) O1) ApplyToResult3[O4, O3, O2, O1]

type ApplyToResult5

type ApplyToResult5[O1, O2, O3, O4, O5, T any] struct {
	// contains filtered or unexported fields
}

func Chain5

func Chain5[Out5, Out4, Out3, Out2, Out1, T any](result Result[T]) ApplyToResult5[Out1, Out2, Out3, Out4, Out5, T]

func (ApplyToResult5[O1, O2, O3, O4, O5, T]) AndThen

func (a ApplyToResult5[O1, O2, O3, O4, O5, T]) AndThen(fn func(T) Result[O1]) ApplyToResult4[O5, O4, O3, O2, O1]

func (ApplyToResult5[O1, O2, O3, O4, O5, T]) Map

func (a ApplyToResult5[O1, O2, O3, O4, O5, T]) Map(fn func(T) O1) ApplyToResult4[O5, O4, O3, O2, O1]

type ApplyToResult6

type ApplyToResult6[O1, O2, O3, O4, O5, O6, T any] struct {
	// contains filtered or unexported fields
}

func Chain6

func Chain6[Out6, Out5, Out4, Out3, Out2, Out1, T any](result Result[T]) ApplyToResult6[Out1, Out2, Out3, Out4, Out5, Out6, T]

func (ApplyToResult6[O1, O2, O3, O4, O5, O6, T]) AndThen

func (a ApplyToResult6[O1, O2, O3, O4, O5, O6, T]) AndThen(fn func(T) Result[O1]) ApplyToResult5[O6, O5, O4, O3, O2, O1]

func (ApplyToResult6[O1, O2, O3, O4, O5, O6, T]) Map

func (a ApplyToResult6[O1, O2, O3, O4, O5, O6, T]) Map(fn func(T) O1) ApplyToResult5[O6, O5, O4, O3, O2, O1]

type ApplyToResult7

type ApplyToResult7[O1, O2, O3, O4, O5, O6, O7, T any] struct {
	// contains filtered or unexported fields
}

func Chain7

func Chain7[Out7, Out6, Out5, Out4, Out3, Out2, Out1, T any](result Result[T]) ApplyToResult7[Out1, Out2, Out3, Out4, Out5, Out6, Out7, T]

func (ApplyToResult7[O1, O2, O3, O4, O5, O6, O7, T]) AndThen

func (a ApplyToResult7[O1, O2, O3, O4, O5, O6, O7, T]) AndThen(fn func(T) Result[O1]) ApplyToResult6[O7, O6, O5, O4, O3, O2, O1]

func (ApplyToResult7[O1, O2, O3, O4, O5, O6, O7, T]) Map

func (a ApplyToResult7[O1, O2, O3, O4, O5, O6, O7, T]) Map(fn func(T) O1) ApplyToResult6[O7, O6, O5, O4, O3, O2, O1]

type ApplyToResult8

type ApplyToResult8[O1, O2, O3, O4, O5, O6, O7, O8, T any] struct {
	// contains filtered or unexported fields
}

func Chain8

func Chain8[Out8, Out7, Out6, Out5, Out4, Out3, Out2, Out1, T any](result Result[T]) ApplyToResult8[Out1, Out2, Out3, Out4, Out5, Out6, Out7, Out8, T]

func (ApplyToResult8[O1, O2, O3, O4, O5, O6, O7, O8, T]) AndThen

func (a ApplyToResult8[O1, O2, O3, O4, O5, O6, O7, O8, T]) AndThen(fn func(T) Result[O1]) ApplyToResult7[O8, O7, O6, O5, O4, O3, O2, O1]

func (ApplyToResult8[O1, O2, O3, O4, O5, O6, O7, O8, T]) Map

func (a ApplyToResult8[O1, O2, O3, O4, O5, O6, O7, O8, T]) Map(fn func(T) O1) ApplyToResult7[O8, O7, O6, O5, O4, O3, O2, O1]

type ApplyToResult9

type ApplyToResult9[O1, O2, O3, O4, O5, O6, O7, O8, O9, T any] struct {
	// contains filtered or unexported fields
}

func Chain9

func Chain9[Out9, Out8, Out7, Out6, Out5, Out4, Out3, Out2, Out1, T any](result Result[T]) ApplyToResult9[Out1, Out2, Out3, Out4, Out5, Out6, Out7, Out8, Out9, T]

func (ApplyToResult9[O1, O2, O3, O4, O5, O6, O7, O8, O9, T]) AndThen

func (a ApplyToResult9[O1, O2, O3, O4, O5, O6, O7, O8, O9, T]) AndThen(fn func(T) Result[O1]) ApplyToResult8[O9, O8, O7, O6, O5, O4, O3, O2, O1]

func (ApplyToResult9[O1, O2, O3, O4, O5, O6, O7, O8, O9, T]) Map

func (a ApplyToResult9[O1, O2, O3, O4, O5, O6, O7, O8, O9, T]) Map(fn func(T) O1) ApplyToResult8[O9, O8, O7, O6, O5, O4, O3, O2, O1]

type Option

type Option[T any] struct {
	// contains filtered or unexported fields
}

func Cast

func Cast[T any](value any) Option[T]

func Maybe

func Maybe[T any](t *T) Option[T]

func None

func None[T any]() Option[T]

func Some

func Some[T any](value T) Option[T]

func (Option[T]) AsPtr

func (o Option[T]) AsPtr() *T

func (Option[T]) Expect

func (o Option[T]) Expect(panicMsg string) T

func (Option[T]) IsNone

func (o Option[T]) IsNone() bool

func (Option[T]) IsSome

func (o Option[T]) IsSome() bool

func (Option[T]) Some

func (o Option[T]) Some(out *T) bool

func (Option[T]) Unwrap

func (o Option[T]) Unwrap() T

func (Option[T]) UnwrapOr

func (o Option[T]) UnwrapOr(defaultValue T) T

func (Option[T]) UnwrapOrElse

func (o Option[T]) UnwrapOrElse(fn func() T) T

type Result

type Result[T any] struct {
	// contains filtered or unexported fields
}

Result[T] is a generic pseudo-enum, used for returning results with errors. The result type eliminates the need to return nil pointers, sentinal type zero values, or partial results when an error has occured. Instead, the result type can be in one of two states: Ok(T) or Err(error).

func AndThen

func AndThen[T, U any](r Result[T], fn func(T) Result[U]) Result[U]

func Err

func Err[T any](err error) Result[T]

Create an error Result[T]

func Map

func Map[T, U any](r Result[T], fn func(T) U) Result[U]

func Map2

func Map2[T, U, V any](r Result[T], s Result[U], fn func(T, U) V) Result[V]

func Map3

func Map3[T, U, V, W any](r Result[T], s Result[U], t Result[V], fn func(T, U, V) W) Result[W]

func MapErr

func MapErr[T any, E error](fn func(error) E, r Result[T]) Result[T]

func NewPtrResult

func NewPtrResult[T any](value *T, err error) Result[T]

func NewResult

func NewResult[T any](value T, err error) Result[T]

func NewTupleResult

func NewTupleResult[T, U any](first T, second U, err error) Result[Tuple[T, U]]

func NewVoidResult

func NewVoidResult(err error) Result[Void]

func Ok

func Ok[T any](value T) Result[T]

Create a successful Result[T]

func (Result[T]) Err

func (r Result[T]) Err() Option[error]

func (Result[T]) Expect

func (r Result[T]) Expect(panicMsg string) T

func (Result[T]) ExpectErr

func (r Result[T]) ExpectErr(panicMsg string) error

func (Result[T]) IsErr

func (r Result[T]) IsErr() bool

Is the result in the Err state

func (Result[T]) IsOk

func (r Result[T]) IsOk() bool

Is the result in the Ok state

func (Result[T]) MapError

func (r Result[T]) MapError(fn func(e error) error) Result[T]

func (Result[T]) Ok

func (r Result[T]) Ok(out *T) error

func (Result[T]) Results

func (r Result[T]) Results() (*T, error)

func (Result[T]) ResultsMappingEmpty

func (r Result[T]) ResultsMappingEmpty() (T, error)

ResultsMapEmpty maps the None case of the result value to an empty T (instead of a nil pointer to a T as is done by `Results()`)

func (Result[T]) Unwrap

func (r Result[T]) Unwrap() T

func (Result[T]) UnwrapErr

func (r Result[T]) UnwrapErr() error

func (Result[T]) UnwrapErrOr

func (r Result[T]) UnwrapErrOr(defaultValue error) error

func (Result[T]) UnwrapOr

func (r Result[T]) UnwrapOr(defaultValue T) T

func (Result[T]) UnwrapOrElse

func (r Result[T]) UnwrapOrElse(fn func(error) T) T

func (Result[T]) Value

func (r Result[T]) Value() Option[T]

func (Result[T]) WrapErr

func (r Result[T]) WrapErr(format string) Result[T]

type Tuple

type Tuple[T, U any] struct {
	First  T
	Second U
}

func (Tuple[T, U]) Destructure

func (t Tuple[T, U]) Destructure() (T, U)

type Void

type Void struct{}

Jump to

Keyboard shortcuts

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