Movatterモバイル変換


[0]ホーム

URL:


mo

packagemodule
v1.13.0Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License:MITImports:9Imported by:285

Details

Repository

github.com/samber/mo

Links

README

mo - Monads

tagGo VersionGoDocBuild StatusGo reportCoverageLicense

🦄samber/mo brings monads and popular FP abstractions to Go projects.samber/mo uses the recent Go 1.18+ Generics.

Inspired by:

  • Scala
  • Rust
  • FP-TS

See also:

  • samber/lo: A Lodash-style Go library based on Go 1.18+ Generics
  • samber/do: A dependency injection toolkit based on Go 1.18+ Generics

Why this name?

I loveshort name for such utility library. This name is similar to "Monad Go" and no Go package uses this name.

💡 Features

We currently support the following data types:

  • Option[T] (Maybe)
  • Result[T]
  • Either[A, B]
  • EitherX[T1, ..., TX] (With X between 3 and 5)
  • Future[T]
  • IO[T]
  • IOEither[T]
  • Task[T]
  • TaskEither[T]
  • State[S, A]

🚀 Install

go get github.com/samber/mo@v1

This library is v1 and follows SemVer strictly.

No breaking changes will be made to exported APIs before v2.0.0.

This library has no dependencies except the Go std lib.

💡 Quick start

You can importmo using:

import (    "github.com/samber/mo")

Then use one of the helpers below:

option1 := mo.Some(42)// Some(42)option1.    FlatMap(func (value int) Option[int] {        return Some(value*2)    }).    FlatMap(func (value int) Option[int] {        return Some(value%2)    }).    FlatMap(func (value int) Option[int] {        return Some(value+21)    }).    OrElse(1234)// 21option2 := mo.None[int]()// Noneoption2.OrElse(1234)// 1234option3 := option1.Match(    func(i int) (int, bool) {        // when value is present        return i * 2, true    },    func() (int, bool) {        // when value is absent        return 0, false    },)// Some(42)

More examples indocumentation.

Tips for lazy developers

I cannot recommend it, but in case you are too lazy for repeatingmo. everywhere, you can import the entire library into the namespace.

import (    . "github.com/samber/mo")

I take no responsibility on this junk. 😁 💩

🤠 Documentation and examples

GoDoc: https://godoc.org/github.com/samber/mo

Option[T any]

Option is a container for an optional value of typeT. If value exists,Option is of typeSome. If the value is absent,Option is of typeNone.

Implements:

  • mo.Foldable[T, U]

Constructors:

Methods:

Other:

  • mo.Fold[T, U, R any](f Foldable[T, U], successFunc func(U) R, failureFunc func(T) R) Rdoc
Result[T any]

Result respresent a result of an action having one of the following output: success or failure. An instance ofResult is an instance of eitherOk orErr. It could be compared toEither[error, T].

Implements:

  • mo.Foldable[T, U]

Constructors:

Methods:

Other:

  • mo.Fold[T, U, R any](f Foldable[T, U], successFunc func(U) R, failureFunc func(T) R) Rdoc
  • mo.Do[T any](fn func() T) (result mo.Result[T])doc
Either[L any, R any]

Either represents a value of 2 possible types. An instance ofEither is an instance of eitherA orB.

Implements:

  • mo.Foldable[T, U]

Constructors:

Methods:

Other:

  • mo.Fold[T, U, R any](f Foldable[T, U], successFunc func(U) R, failureFunc func(T) R) Rdoc
EitherX[T1, ..., TX] (With X between 3 and 5)

EitherX respresents a value of X possible types. For example, anEither3 value is eitherT1,T2 orT3.

Constructors:

  • mo.NewEitherXArgY()doc. Eg:
    • mo.NewEither3Arg1[A, B, C](A)
    • mo.NewEither3Arg2[A, B, C](B)
    • mo.NewEither3Arg3[A, B, C](C)
    • mo.NewEither4Arg1[A, B, C, D](A)
    • mo.NewEither4Arg2[A, B, C, D](B)
    • ...

Methods:

Future[T any]

Future represents a value which may or may not currently be available, but will be available at some point, or an exception if that value could not be made available.

Constructors:

  • mo.NewFuture()doc

Methods:

IO[T any]

IO represents a non-deterministic synchronous computation that can cause side effects, yields a value of typeR and never fails.

Constructors:

Methods:

IOEither[T any]

IO represents a non-deterministic synchronous computation that can cause side effects, yields a value of typeR and can fail.

Constructors:

  • mo.NewIOEither()doc
  • mo.NewIOEither1()doc
  • mo.NewIOEither2()doc
  • mo.NewIOEither3()doc
  • mo.NewIOEither4()doc
  • mo.NewIOEither5()doc

Methods:

Task[T any]

Task represents a non-deterministic asynchronous computation that can cause side effects, yields a value of typeR and never fails.

Constructors:

  • mo.NewTask()doc
  • mo.NewTask1()doc
  • mo.NewTask2()doc
  • mo.NewTask3()doc
  • mo.NewTask4()doc
  • mo.NewTask5()doc
  • mo.NewTaskFromIO()doc
  • mo.NewTaskFromIO1()doc
  • mo.NewTaskFromIO2()doc
  • mo.NewTaskFromIO3()doc
  • mo.NewTaskFromIO4()doc
  • mo.NewTaskFromIO5()doc

Methods:

TaskEither[T any]

TaskEither represents a non-deterministic asynchronous computation that can cause side effects, yields a value of typeR and can fail.

Constructors:

  • mo.NewTaskEither()doc
  • mo.NewTaskEitherFromIOEither()doc

Methods:

State[S any, A any]

State represents a function(S) -> (A, S), whereS is state,A is result.

Constructors:

  • mo.NewState()doc
  • mo.ReturnState()doc

Methods:

Foldable[T, U]

Foldable represents a type that can be folded into a single value based on its state.

  • mo.Fold[T, U, R any](f Foldable[T, U], successFunc func(U) R, failureFunc func(T) R) Rdoc

🛩 Benchmark

// @TODO

This library does not usereflect package. We don't expect overhead.

🤝 Contributing

Don't hesitate ;)

With Docker
docker-compose run --rm dev
Without Docker
# Install some dev dependenciesmake tools# Run testsmake test# ormake watch-test

👤 Contributors

Contributors

💫 Show your support

Give a ⭐️ if this project helped you!

GitHub Sponsors

📝 License

Copyright © 2022Samuel Berthe.

This project isMIT licensed.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

funcFoldadded inv1.12.0

func Fold[T, U, Rany](fFoldable[T, U], successFunc func(U) R, failureFunc func(T) R) R

Fold applies one of the two functions based on the state of the Foldable type,and it returns the result of applying either successFunc or failureFunc.

- T: the type of the failure value (e.g., an error type)- U: the type of the success value- R: the type of the return value from the folding functions

successFunc is applied when the Foldable is in the success state (i.e., isLeft() is false).failureFunc is applied when the Foldable is in the failure state (i.e., isLeft() is true).

Types

typeEither

type Either[Lany, Rany] struct {// contains filtered or unexported fields}

Either respresents a value of 2 possible types.An instance of Either is an instance of either A or B.

funcLeft

func Left[Lany, Rany](value L)Either[L, R]

Left builds the left side of the Either struct, as opposed to the Right side.

funcRight

func Right[Lany, Rany](value R)Either[L, R]

Right builds the right side of the Either struct, as opposed to the Left side.

func (Either[L, R])ForEach

func (eEither[L, R]) ForEach(leftCb func(L), rightCb func(R))

ForEach executes the given side-effecting function, depending of value is Left or Right.

func (Either[L, R])IsLeft

func (eEither[L, R]) IsLeft()bool

IsLeft returns true if Either is an instance of Left.

func (Either[L, R])IsRight

func (eEither[L, R]) IsRight()bool

IsRight returns true if Either is an instance of Right.

func (Either[L, R])Left

func (eEither[L, R]) Left() (L,bool)

Left returns left value of a Either struct.

func (Either[L, R])LeftOrElse

func (eEither[L, R]) LeftOrElse(fallback L) L

LeftOrElse returns left value of a Either struct or fallback.

func (Either[L, R])LeftOrEmpty

func (eEither[L, R]) LeftOrEmpty() L

LeftOrEmpty returns left value of a Either struct or empty value.

func (Either[L, R])MapLeft

func (eEither[L, R]) MapLeft(mapper func(L)Either[L, R])Either[L, R]

MapLeft executes the given function, if Either is of type Left, and returns result.

func (Either[L, R])MapRight

func (eEither[L, R]) MapRight(mapper func(R)Either[L, R])Either[L, R]

MapRight executes the given function, if Either is of type Right, and returns result.

func (Either[L, R])Match

func (eEither[L, R]) Match(onLeft func(L)Either[L, R], onRight func(R)Either[L, R])Either[L, R]

Match executes the given function, depending of value is Left or Right, and returns result.

func (Either[L, R])MustLeft

func (eEither[L, R]) MustLeft() L

MustLeft returns left value of a Either struct or panics.

func (Either[L, R])MustRight

func (eEither[L, R]) MustRight() R

MustRight returns right value of a Either struct or panics.

func (Either[L, R])Right

func (eEither[L, R]) Right() (R,bool)

Right returns right value of a Either struct.

func (Either[L, R])RightOrElse

func (eEither[L, R]) RightOrElse(fallback R) R

RightOrElse returns right value of a Either struct or fallback.

func (Either[L, R])RightOrEmpty

func (eEither[L, R]) RightOrEmpty() R

RightOrEmpty returns right value of a Either struct or empty value.

func (Either[L, R])Swap

func (eEither[L, R]) Swap()Either[R, L]

Swap returns the left value in Right and vice versa.

func (Either[L, R])Unpackadded inv1.6.0

func (eEither[L, R]) Unpack() (L, R)

Unpack returns all values

typeEither3added inv1.2.0

type Either3[T1any, T2any, T3any] struct {// contains filtered or unexported fields}

Either3 represents a value of 3 possible types.An instance of Either3 is an instance of either T1, T2 or T3.

funcNewEither3Arg1added inv1.2.0

func NewEither3Arg1[T1any, T2any, T3any](value T1)Either3[T1, T2, T3]

NewEither3Arg1 builds the first argument of the Either3 struct.

funcNewEither3Arg2added inv1.2.0

func NewEither3Arg2[T1any, T2any, T3any](value T2)Either3[T1, T2, T3]

NewEither3Arg2 builds the second argument of the Either3 struct.

funcNewEither3Arg3added inv1.2.0

func NewEither3Arg3[T1any, T2any, T3any](value T3)Either3[T1, T2, T3]

NewEither3Arg3 builds the third argument of the Either3 struct.

func (Either3[T1, T2, T3])Arg1added inv1.2.0

func (eEither3[T1, T2, T3]) Arg1() (T1,bool)

Arg1 returns the first argument of a Either3 struct.

func (Either3[T1, T2, T3])Arg1OrElseadded inv1.2.0

func (eEither3[T1, T2, T3]) Arg1OrElse(fallback T1) T1

Arg1OrElse returns the first argument of a Either3 struct or fallback.

func (Either3[T1, T2, T3])Arg1OrEmptyadded inv1.2.0

func (eEither3[T1, T2, T3]) Arg1OrEmpty() T1

Arg1OrEmpty returns the first argument of a Either3 struct or empty value.

func (Either3[T1, T2, T3])Arg2added inv1.2.0

func (eEither3[T1, T2, T3]) Arg2() (T2,bool)

Arg2 returns the second argument of a Either3 struct.

func (Either3[T1, T2, T3])Arg2OrElseadded inv1.2.0

func (eEither3[T1, T2, T3]) Arg2OrElse(fallback T2) T2

Arg2OrElse returns the second argument of a Either3 struct or fallback.

func (Either3[T1, T2, T3])Arg2OrEmptyadded inv1.2.0

func (eEither3[T1, T2, T3]) Arg2OrEmpty() T2

Arg2OrEmpty returns the second argument of a Either3 struct or empty value.

func (Either3[T1, T2, T3])Arg3added inv1.2.0

func (eEither3[T1, T2, T3]) Arg3() (T3,bool)

Arg3 returns the third argument of a Either3 struct.

func (Either3[T1, T2, T3])Arg3OrElseadded inv1.2.0

func (eEither3[T1, T2, T3]) Arg3OrElse(fallback T3) T3

Arg3OrElse returns the third argument of a Either3 struct or fallback.

func (Either3[T1, T2, T3])Arg3OrEmptyadded inv1.2.0

func (eEither3[T1, T2, T3]) Arg3OrEmpty() T3

Arg3OrEmpty returns the third argument of a Either3 struct or empty value.

func (Either3[T1, T2, T3])ForEachadded inv1.2.0

func (eEither3[T1, T2, T3]) ForEach(arg1Cb func(T1), arg2Cb func(T2), arg3Cb func(T3))

ForEach executes the given side-effecting function, depending of the argument set.

func (Either3[T1, T2, T3])IsArg1added inv1.2.0

func (eEither3[T1, T2, T3]) IsArg1()bool

IsArg1 returns true if Either3 uses the first argument.

func (Either3[T1, T2, T3])IsArg2added inv1.2.0

func (eEither3[T1, T2, T3]) IsArg2()bool

IsArg2 returns true if Either3 uses the second argument.

func (Either3[T1, T2, T3])IsArg3added inv1.2.0

func (eEither3[T1, T2, T3]) IsArg3()bool

IsArg3 returns true if Either3 uses the third argument.

func (Either3[T1, T2, T3])MapArg1added inv1.2.0

func (eEither3[T1, T2, T3]) MapArg1(mapper func(T1)Either3[T1, T2, T3])Either3[T1, T2, T3]

MapArg1 executes the given function, if Either3 use the first argument, and returns result.

func (Either3[T1, T2, T3])MapArg2added inv1.2.0

func (eEither3[T1, T2, T3]) MapArg2(mapper func(T2)Either3[T1, T2, T3])Either3[T1, T2, T3]

MapArg2 executes the given function, if Either3 use the second argument, and returns result.

func (Either3[T1, T2, T3])MapArg3added inv1.2.0

func (eEither3[T1, T2, T3]) MapArg3(mapper func(T3)Either3[T1, T2, T3])Either3[T1, T2, T3]

MapArg3 executes the given function, if Either3 use the third argument, and returns result.

func (Either3[T1, T2, T3])Matchadded inv1.2.0

func (eEither3[T1, T2, T3]) Match(onArg1 func(T1)Either3[T1, T2, T3],onArg2 func(T2)Either3[T1, T2, T3],onArg3 func(T3)Either3[T1, T2, T3])Either3[T1, T2, T3]

Match executes the given function, depending of the argument set, and returns result.

func (Either3[T1, T2, T3])MustArg1added inv1.2.0

func (eEither3[T1, T2, T3]) MustArg1() T1

MustArg1 returns the first argument of a Either3 struct or panics.

func (Either3[T1, T2, T3])MustArg2added inv1.2.0

func (eEither3[T1, T2, T3]) MustArg2() T2

MustArg2 returns the second argument of a Either3 struct or panics.

func (Either3[T1, T2, T3])MustArg3added inv1.2.0

func (eEither3[T1, T2, T3]) MustArg3() T3

MustArg3 returns the third argument of a Either3 struct or panics.

func (Either3[T1, T2, T3])Unpackadded inv1.6.0

func (eEither3[T1, T2, T3]) Unpack() (T1, T2, T3)

Unpack returns all values

typeEither4added inv1.2.0

type Either4[T1any, T2any, T3any, T4any] struct {// contains filtered or unexported fields}

Either4 respresents a value of 4 possible types.An instance of Either4 is an instance of either T1, T2, T3 or T4.

funcNewEither4Arg1added inv1.2.0

func NewEither4Arg1[T1any, T2any, T3any, T4any](value T1)Either4[T1, T2, T3, T4]

NewEither4Arg1 builds the first argument of the Either4 struct.

funcNewEither4Arg2added inv1.2.0

func NewEither4Arg2[T1any, T2any, T3any, T4any](value T2)Either4[T1, T2, T3, T4]

NewEither4Arg2 builds the second argument of the Either4 struct.

funcNewEither4Arg3added inv1.2.0

func NewEither4Arg3[T1any, T2any, T3any, T4any](value T3)Either4[T1, T2, T3, T4]

NewEither4Arg3 builds the third argument of the Either4 struct.

funcNewEither4Arg4added inv1.2.0

func NewEither4Arg4[T1any, T2any, T3any, T4any](value T4)Either4[T1, T2, T3, T4]

NewEither4Arg4 builds the fourth argument of the Either4 struct.

func (Either4[T1, T2, T3, T4])Arg1added inv1.2.0

func (eEither4[T1, T2, T3, T4]) Arg1() (T1,bool)

Arg1 returns the first argument of a Either4 struct.

func (Either4[T1, T2, T3, T4])Arg1OrElseadded inv1.2.0

func (eEither4[T1, T2, T3, T4]) Arg1OrElse(fallback T1) T1

Arg1OrElse returns the first argument of a Either4 struct or fallback.

func (Either4[T1, T2, T3, T4])Arg1OrEmptyadded inv1.2.0

func (eEither4[T1, T2, T3, T4]) Arg1OrEmpty() T1

Arg1OrEmpty returns the first argument of a Either4 struct or empty value.

func (Either4[T1, T2, T3, T4])Arg2added inv1.2.0

func (eEither4[T1, T2, T3, T4]) Arg2() (T2,bool)

Arg2 returns the second argument of a Either4 struct.

func (Either4[T1, T2, T3, T4])Arg2OrElseadded inv1.2.0

func (eEither4[T1, T2, T3, T4]) Arg2OrElse(fallback T2) T2

Arg2OrElse returns the second argument of a Either4 struct or fallback.

func (Either4[T1, T2, T3, T4])Arg2OrEmptyadded inv1.2.0

func (eEither4[T1, T2, T3, T4]) Arg2OrEmpty() T2

Arg2OrEmpty returns the second argument of a Either4 struct or empty value.

func (Either4[T1, T2, T3, T4])Arg3added inv1.2.0

func (eEither4[T1, T2, T3, T4]) Arg3() (T3,bool)

Arg3 returns the third argument of a Either4 struct.

func (Either4[T1, T2, T3, T4])Arg3OrElseadded inv1.2.0

func (eEither4[T1, T2, T3, T4]) Arg3OrElse(fallback T3) T3

Arg3OrElse returns the third argument of a Either4 struct or fallback.

func (Either4[T1, T2, T3, T4])Arg3OrEmptyadded inv1.2.0

func (eEither4[T1, T2, T3, T4]) Arg3OrEmpty() T3

Arg3OrEmpty returns the third argument of a Either4 struct or empty value.

func (Either4[T1, T2, T3, T4])Arg4added inv1.2.0

func (eEither4[T1, T2, T3, T4]) Arg4() (T4,bool)

Arg4 returns the fourth argument of a Either4 struct.

func (Either4[T1, T2, T3, T4])Arg4OrElseadded inv1.2.0

func (eEither4[T1, T2, T3, T4]) Arg4OrElse(fallback T4) T4

Arg4OrElse returns the fourth argument of a Either4 struct or fallback.

func (Either4[T1, T2, T3, T4])Arg4OrEmptyadded inv1.2.0

func (eEither4[T1, T2, T3, T4]) Arg4OrEmpty() T4

Arg4OrEmpty returns the fourth argument of a Either4 struct or empty value.

func (Either4[T1, T2, T3, T4])ForEachadded inv1.2.0

func (eEither4[T1, T2, T3, T4]) ForEach(arg1Cb func(T1), arg2Cb func(T2), arg3Cb func(T3), arg4Cb func(T4))

ForEach executes the given side-effecting function, depending of the argument set.

func (Either4[T1, T2, T3, T4])IsArg1added inv1.2.0

func (eEither4[T1, T2, T3, T4]) IsArg1()bool

IsArg1 returns true if Either4 uses the first argument.

func (Either4[T1, T2, T3, T4])IsArg2added inv1.2.0

func (eEither4[T1, T2, T3, T4]) IsArg2()bool

IsArg2 returns true if Either4 uses the second argument.

func (Either4[T1, T2, T3, T4])IsArg3added inv1.2.0

func (eEither4[T1, T2, T3, T4]) IsArg3()bool

IsArg3 returns true if Either4 uses the third argument.

func (Either4[T1, T2, T3, T4])IsArg4added inv1.2.0

func (eEither4[T1, T2, T3, T4]) IsArg4()bool

IsArg4 returns true if Either4 uses the fourth argument.

func (Either4[T1, T2, T3, T4])MapArg1added inv1.2.0

func (eEither4[T1, T2, T3, T4]) MapArg1(mapper func(T1)Either4[T1, T2, T3, T4])Either4[T1, T2, T3, T4]

MapArg1 executes the given function, if Either4 use the first argument, and returns result.

func (Either4[T1, T2, T3, T4])MapArg2added inv1.2.0

func (eEither4[T1, T2, T3, T4]) MapArg2(mapper func(T2)Either4[T1, T2, T3, T4])Either4[T1, T2, T3, T4]

MapArg2 executes the given function, if Either4 use the second argument, and returns result.

func (Either4[T1, T2, T3, T4])MapArg3added inv1.2.0

func (eEither4[T1, T2, T3, T4]) MapArg3(mapper func(T3)Either4[T1, T2, T3, T4])Either4[T1, T2, T3, T4]

MapArg3 executes the given function, if Either4 use the third argument, and returns result.

func (Either4[T1, T2, T3, T4])MapArg4added inv1.2.0

func (eEither4[T1, T2, T3, T4]) MapArg4(mapper func(T4)Either4[T1, T2, T3, T4])Either4[T1, T2, T3, T4]

MapArg4 executes the given function, if Either4 use the fourth argument, and returns result.

func (Either4[T1, T2, T3, T4])Matchadded inv1.2.0

func (eEither4[T1, T2, T3, T4]) Match(onArg1 func(T1)Either4[T1, T2, T3, T4],onArg2 func(T2)Either4[T1, T2, T3, T4],onArg3 func(T3)Either4[T1, T2, T3, T4],onArg4 func(T4)Either4[T1, T2, T3, T4])Either4[T1, T2, T3, T4]

Match executes the given function, depending of the argument set, and returns result.

func (Either4[T1, T2, T3, T4])MustArg1added inv1.2.0

func (eEither4[T1, T2, T3, T4]) MustArg1() T1

MustArg1 returns the first argument of a Either4 struct or panics.

func (Either4[T1, T2, T3, T4])MustArg2added inv1.2.0

func (eEither4[T1, T2, T3, T4]) MustArg2() T2

MustArg2 returns the second argument of a Either4 struct or panics.

func (Either4[T1, T2, T3, T4])MustArg3added inv1.2.0

func (eEither4[T1, T2, T3, T4]) MustArg3() T3

MustArg3 returns the third argument of a Either4 struct or panics.

func (Either4[T1, T2, T3, T4])MustArg4added inv1.2.0

func (eEither4[T1, T2, T3, T4]) MustArg4() T4

MustArg4 returns the fourth argument of a Either4 struct or panics.

func (Either4[T1, T2, T3, T4])Unpackadded inv1.6.0

func (eEither4[T1, T2, T3, T4]) Unpack() (T1, T2, T3, T4)

Unpack returns all values

typeEither5added inv1.2.0

type Either5[T1any, T2any, T3any, T4any, T5any] struct {// contains filtered or unexported fields}

Either5 respresents a value of 5 possible types.An instance of Either5 is an instance of either T1, T2, T3, T4, or T5.

funcNewEither5Arg1added inv1.2.0

func NewEither5Arg1[T1any, T2any, T3any, T4any, T5any](value T1)Either5[T1, T2, T3, T4, T5]

NewEither5Arg1 builds the first argument of the Either5 struct.

funcNewEither5Arg2added inv1.2.0

func NewEither5Arg2[T1any, T2any, T3any, T4any, T5any](value T2)Either5[T1, T2, T3, T4, T5]

NewEither5Arg2 builds the second argument of the Either5 struct.

funcNewEither5Arg3added inv1.2.0

func NewEither5Arg3[T1any, T2any, T3any, T4any, T5any](value T3)Either5[T1, T2, T3, T4, T5]

NewEither5Arg3 builds the third argument of the Either5 struct.

funcNewEither5Arg4added inv1.2.0

func NewEither5Arg4[T1any, T2any, T3any, T4any, T5any](value T4)Either5[T1, T2, T3, T4, T5]

NewEither5Arg4 builds the fourth argument of the Either5 struct.

funcNewEither5Arg5added inv1.2.0

func NewEither5Arg5[T1any, T2any, T3any, T4any, T5any](value T5)Either5[T1, T2, T3, T4, T5]

NewEither5Arg5 builds the fith argument of the Either5 struct.

func (Either5[T1, T2, T3, T4, T5])Arg1added inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) Arg1() (T1,bool)

Arg1 returns the first argument of a Either5 struct.

func (Either5[T1, T2, T3, T4, T5])Arg1OrElseadded inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) Arg1OrElse(fallback T1) T1

Arg1OrElse returns the first argument of a Either5 struct or fallback.

func (Either5[T1, T2, T3, T4, T5])Arg1OrEmptyadded inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) Arg1OrEmpty() T1

Arg1OrEmpty returns the first argument of a Either5 struct or empty value.

func (Either5[T1, T2, T3, T4, T5])Arg2added inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) Arg2() (T2,bool)

Arg2 returns the second argument of a Either5 struct.

func (Either5[T1, T2, T3, T4, T5])Arg2OrElseadded inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) Arg2OrElse(fallback T2) T2

Arg2OrElse returns the second argument of a Either5 struct or fallback.

func (Either5[T1, T2, T3, T4, T5])Arg2OrEmptyadded inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) Arg2OrEmpty() T2

Arg2OrEmpty returns the second argument of a Either5 struct or empty value.

func (Either5[T1, T2, T3, T4, T5])Arg3added inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) Arg3() (T3,bool)

Arg3 returns the third argument of a Either5 struct.

func (Either5[T1, T2, T3, T4, T5])Arg3OrElseadded inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) Arg3OrElse(fallback T3) T3

Arg3OrElse returns the third argument of a Either5 struct or fallback.

func (Either5[T1, T2, T3, T4, T5])Arg3OrEmptyadded inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) Arg3OrEmpty() T3

Arg3OrEmpty returns the third argument of a Either5 struct or empty value.

func (Either5[T1, T2, T3, T4, T5])Arg4added inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) Arg4() (T4,bool)

Arg4 returns the fourth argument of a Either5 struct.

func (Either5[T1, T2, T3, T4, T5])Arg4OrElseadded inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) Arg4OrElse(fallback T4) T4

Arg4OrElse returns the fourth argument of a Either5 struct or fallback.

func (Either5[T1, T2, T3, T4, T5])Arg4OrEmptyadded inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) Arg4OrEmpty() T4

Arg4OrEmpty returns the fourth argument of a Either5 struct or empty value.

func (Either5[T1, T2, T3, T4, T5])Arg5added inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) Arg5() (T5,bool)

Arg5 returns the fith argument of a Either5 struct.

func (Either5[T1, T2, T3, T4, T5])Arg5OrElseadded inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) Arg5OrElse(fallback T5) T5

Arg5OrElse returns the fith argument of a Either5 struct or fallback.

func (Either5[T1, T2, T3, T4, T5])Arg5OrEmptyadded inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) Arg5OrEmpty() T5

Arg5OrEmpty returns the fifth argument of a Either5 struct or empty value.

func (Either5[T1, T2, T3, T4, T5])ForEachadded inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) ForEach(arg1Cb func(T1), arg2Cb func(T2), arg3Cb func(T3), arg4Cb func(T4), arg5Cb func(T5))

ForEach executes the given side-effecting function, depending of the argument set.

func (Either5[T1, T2, T3, T4, T5])IsArg1added inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) IsArg1()bool

IsArg1 returns true if Either5 uses the first argument.

func (Either5[T1, T2, T3, T4, T5])IsArg2added inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) IsArg2()bool

IsArg2 returns true if Either5 uses the second argument.

func (Either5[T1, T2, T3, T4, T5])IsArg3added inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) IsArg3()bool

IsArg3 returns true if Either5 uses the third argument.

func (Either5[T1, T2, T3, T4, T5])IsArg4added inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) IsArg4()bool

IsArg4 returns true if Either5 uses the fourth argument.

func (Either5[T1, T2, T3, T4, T5])IsArg5added inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) IsArg5()bool

IsArg5 returns true if Either5 uses the fith argument.

func (Either5[T1, T2, T3, T4, T5])MapArg1added inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) MapArg1(mapper func(T1)Either5[T1, T2, T3, T4, T5])Either5[T1, T2, T3, T4, T5]

MapArg1 executes the given function, if Either5 use the first argument, and returns result.

func (Either5[T1, T2, T3, T4, T5])MapArg2added inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) MapArg2(mapper func(T2)Either5[T1, T2, T3, T4, T5])Either5[T1, T2, T3, T4, T5]

MapArg2 executes the given function, if Either5 use the second argument, and returns result.

func (Either5[T1, T2, T3, T4, T5])MapArg3added inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) MapArg3(mapper func(T3)Either5[T1, T2, T3, T4, T5])Either5[T1, T2, T3, T4, T5]

MapArg3 executes the given function, if Either5 use the third argument, and returns result.

func (Either5[T1, T2, T3, T4, T5])MapArg4added inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) MapArg4(mapper func(T4)Either5[T1, T2, T3, T4, T5])Either5[T1, T2, T3, T4, T5]

MapArg4 executes the given function, if Either5 use the fourth argument, and returns result.

func (Either5[T1, T2, T3, T4, T5])MapArg5added inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) MapArg5(mapper func(T5)Either5[T1, T2, T3, T4, T5])Either5[T1, T2, T3, T4, T5]

MapArg5 executes the given function, if Either5 use the fith argument, and returns result.

func (Either5[T1, T2, T3, T4, T5])Matchadded inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) Match(onArg1 func(T1)Either5[T1, T2, T3, T4, T5],onArg2 func(T2)Either5[T1, T2, T3, T4, T5],onArg3 func(T3)Either5[T1, T2, T3, T4, T5],onArg4 func(T4)Either5[T1, T2, T3, T4, T5],onArg5 func(T5)Either5[T1, T2, T3, T4, T5])Either5[T1, T2, T3, T4, T5]

Match executes the given function, depending of the argument set, and returns result.

func (Either5[T1, T2, T3, T4, T5])MustArg1added inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) MustArg1() T1

MustArg1 returns the first argument of a Either5 struct or panics.

func (Either5[T1, T2, T3, T4, T5])MustArg2added inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) MustArg2() T2

MustArg2 returns the second argument of a Either5 struct or panics.

func (Either5[T1, T2, T3, T4, T5])MustArg3added inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) MustArg3() T3

MustArg3 returns the third argument of a Either5 struct or panics.

func (Either5[T1, T2, T3, T4, T5])MustArg4added inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) MustArg4() T4

MustArg4 returns the fourth argument of a Either5 struct or panics.

func (Either5[T1, T2, T3, T4, T5])MustArg5added inv1.2.0

func (eEither5[T1, T2, T3, T4, T5]) MustArg5() T5

MustArg5 returns the fith argument of a Either5 struct or panics.

func (Either5[T1, T2, T3, T4, T5])Unpackadded inv1.6.0

func (eEither5[T1, T2, T3, T4, T5]) Unpack() (T1, T2, T3, T4, T5)

Unpack returns all values

typeFoldableadded inv1.12.0

type Foldable[Tany, Uany] interface {// contains filtered or unexported methods}

Foldable represents a type that can be folded into a single valuebased on its state.

- T: the type of the value in the failure state (e.g., an error type).- U: the type of the value in the success state.

typeFuture

type Future[Tany] struct {// contains filtered or unexported fields}

Future represents a value which may or may not currently be available, but will beavailable at some point, or an exception if that value could not be made available.

funcNewFuture

func NewFuture[Tany](cb func(resolve func(T), reject func(error))) *Future[T]

NewFuture instanciate a new future.

func (*Future[T])Cancel

func (f *Future[T]) Cancel()

Cancel cancels the Future chain.

func (*Future[T])Catch

func (f *Future[T]) Catch(cb func(error) (T,error)) *Future[T]

Catch is called when Future is rejected. It returns a new Future.

func (*Future[T])Collect

func (f *Future[T]) Collect() (T,error)

Collect awaits and return result of the Future.

func (*Future[T])Either

func (f *Future[T]) Either()Either[error, T]

Either wraps Collect and returns a Either.

func (*Future[T])Finally

func (f *Future[T]) Finally(cb func(T,error) (T,error)) *Future[T]

Finally is called when Future is processed either resolved or rejected. It returns a new Future.

func (*Future[T])Result

func (f *Future[T]) Result()Result[T]

Result wraps Collect and returns a Result.

func (*Future[T])Then

func (f *Future[T]) Then(cb func(T) (T,error)) *Future[T]

Then is called when Future is resolved. It returns a new Future.

typeIO

type IO[Rany] struct {// contains filtered or unexported fields}

IO represents a non-deterministic synchronous computation thatcan cause side effects, yields a value of type `R` and never fails.

funcNewIO

func NewIO[Rany](f f0[R])IO[R]

NewIO instanciates a new IO.

func (IO[R])Run

func (ioIO[R]) Run() R

Run execute the non-deterministic synchronous computation, with side effect.

typeIO1

type IO1[Rany, Aany] struct {// contains filtered or unexported fields}

IO1 represents a non-deterministic synchronous computation thatcan cause side effects, yields a value of type `R` and never fails.

funcNewIO1

func NewIO1[Rany, Aany](f f1[R, A])IO1[R, A]

NewIO1 instanciates a new IO1.

func (IO1[R, A])Run

func (ioIO1[R, A]) Run(a A) R

Run execute the non-deterministic synchronous computation, with side effect.

typeIO2

type IO2[Rany, Aany, Bany] struct {// contains filtered or unexported fields}

IO2 represents a non-deterministic synchronous computation thatcan cause side effects, yields a value of type `R` and never fails.

funcNewIO2

func NewIO2[Rany, Aany, Bany](f f2[R, A, B])IO2[R, A, B]

NewIO2 instanciates a new IO2.

func (IO2[R, A, B])Run

func (ioIO2[R, A, B]) Run(a A, b B) R

Run execute the non-deterministic synchronous computation, with side effect.

typeIO3

type IO3[Rany, Aany, Bany, Cany] struct {// contains filtered or unexported fields}

IO3 represents a non-deterministic synchronous computation thatcan cause side effects, yields a value of type `R` and never fails.

funcNewIO3

func NewIO3[Rany, Aany, Bany, Cany](f f3[R, A, B, C])IO3[R, A, B, C]

NewIO3 instanciates a new IO3.

func (IO3[R, A, B, C])Run

func (ioIO3[R, A, B, C]) Run(a A, b B, c C) R

Run execute the non-deterministic synchronous computation, with side effect.

typeIO4

type IO4[Rany, Aany, Bany, Cany, Dany] struct {// contains filtered or unexported fields}

IO4 represents a non-deterministic synchronous computation thatcan cause side effects, yields a value of type `R` and never fails.

funcNewIO4

func NewIO4[Rany, Aany, Bany, Cany, Dany](f f4[R, A, B, C, D])IO4[R, A, B, C, D]

NewIO4 instanciates a new IO4.

func (IO4[R, A, B, C, D])Run

func (ioIO4[R, A, B, C, D]) Run(a A, b B, c C, d D) R

Run execute the non-deterministic synchronous computation, with side effect.

typeIO5

type IO5[Rany, Aany, Bany, Cany, Dany, Eany] struct {// contains filtered or unexported fields}

IO5 represents a non-deterministic synchronous computation thatcan cause side effects, yields a value of type `R` and never fails.

funcNewIO5

func NewIO5[Rany, Aany, Bany, Cany, Dany, Eany](f f5[R, A, B, C, D, E])IO5[R, A, B, C, D, E]

NewIO5 instanciates a new IO5.

func (IO5[R, A, B, C, D, E])Run

func (ioIO5[R, A, B, C, D, E]) Run(a A, b B, c C, d D, e E) R

Run execute the non-deterministic synchronous computation, with side effect.

typeIOEither

type IOEither[Rany] struct {// contains filtered or unexported fields}

IOEither represents a non-deterministic synchronous computation thatcan cause side effects, yields a value of type `R` and can fail.

funcNewIOEither

func NewIOEither[Rany](f fe0[R])IOEither[R]

NewIOEither instanciates a new IO.

func (IOEither[R])Run

func (ioIOEither[R]) Run()Either[error, R]

Run execute the non-deterministic synchronous computation, with side effect.

typeIOEither1

type IOEither1[Rany, Aany] struct {// contains filtered or unexported fields}

IOEither1 represents a non-deterministic synchronous computation thatcan cause side effects, yields a value of type `R` and can fail.

funcNewIOEither1

func NewIOEither1[Rany, Aany](f fe1[R, A])IOEither1[R, A]

NewIOEither1 instanciates a new IO1.

func (IOEither1[R, A])Run

func (ioIOEither1[R, A]) Run(a A)Either[error, R]

Run execute the non-deterministic synchronous computation, with side effect.

typeIOEither2

type IOEither2[Rany, Aany, Bany] struct {// contains filtered or unexported fields}

IOEither2 represents a non-deterministic synchronous computation thatcan cause side effects, yields a value of type `R` and can fail.

funcNewIOEither2

func NewIOEither2[Rany, Aany, Bany](f fe2[R, A, B])IOEither2[R, A, B]

NewIOEither2 instanciates a new IO2.

func (IOEither2[R, A, B])Run

func (ioIOEither2[R, A, B]) Run(a A, b B)Either[error, R]

Run execute the non-deterministic synchronous computation, with side effect.

typeIOEither3

type IOEither3[Rany, Aany, Bany, Cany] struct {// contains filtered or unexported fields}

IOEither3 represents a non-deterministic synchronous computation thatcan cause side effects, yields a value of type `R` and can fail.

funcNewIOEither3

func NewIOEither3[Rany, Aany, Bany, Cany](f fe3[R, A, B, C])IOEither3[R, A, B, C]

NewIOEither3 instanciates a new IO3.

func (IOEither3[R, A, B, C])Run

func (ioIOEither3[R, A, B, C]) Run(a A, b B, c C)Either[error, R]

Run execute the non-deterministic synchronous computation, with side effect.

typeIOEither4

type IOEither4[Rany, Aany, Bany, Cany, Dany] struct {// contains filtered or unexported fields}

IOEither4 represents a non-deterministic synchronous computation thatcan cause side effects, yields a value of type `R` and can fail.

funcNewIOEither4

func NewIOEither4[Rany, Aany, Bany, Cany, Dany](f fe4[R, A, B, C, D])IOEither4[R, A, B, C, D]

NewIOEither4 instanciates a new IO4.

func (IOEither4[R, A, B, C, D])Run

func (ioIOEither4[R, A, B, C, D]) Run(a A, b B, c C, d D)Either[error, R]

Run execute the non-deterministic synchronous computation, with side effect.

typeIOEither5

type IOEither5[Rany, Aany, Bany, Cany, Dany, Eany] struct {// contains filtered or unexported fields}

IOEither5 represents a non-deterministic synchronous computation thatcan cause side effects, yields a value of type `R` and can fail.

funcNewIOEither5

func NewIOEither5[Rany, Aany, Bany, Cany, Dany, Eany](f fe5[R, A, B, C, D, E])IOEither5[R, A, B, C, D, E]

NewIOEither5 instanciates a new IO5.

func (IOEither5[R, A, B, C, D, E])Run

func (ioIOEither5[R, A, B, C, D, E]) Run(a A, b B, c C, d D, e E)Either[error, R]

Run execute the non-deterministic synchronous computation, with side effect.

typeOption

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

Option is a container for an optional value of type T. If value exists, Option isof type Some. If the value is absent, Option is of type None.

funcEmptyableToOptionadded inv1.5.0

func EmptyableToOption[Tany](value T)Option[T]

EmptyableToOption builds a Some Option when value is not empty, or None.Play:https://go.dev/play/p/GSpQQ-q-UES

funcNone

func None[Tany]()Option[T]

None builds an Option when value is absent.Play:https://go.dev/play/p/yYQPsYCSYlD

funcPointerToOptionadded inv1.8.0

func PointerToOption[Tany](value *T)Option[T]

PointerToOption builds a Some Option when value is not nil, or None.Play:https://go.dev/play/p/yPVMj4DUb-I

funcSome

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

Some builds an Option when value is present.Play:https://go.dev/play/p/iqz2n9n0tDM

funcTupleToOption

func TupleToOption[Tany](value T, okbool)Option[T]

TupleToOption builds a Some Option when second argument is true, or None.Play:https://go.dev/play/p/gkrg2pZwOty

func (Option[T])FlatMap

func (oOption[T]) FlatMap(mapper func(value T)Option[T])Option[T]

FlatMap executes the mapper function if value is present or returns None if absent.Play:https://go.dev/play/p/OXO-zJx6n5r

func (Option[T])ForEach

func (oOption[T]) ForEach(onValue func(value T))

ForEach executes the given side-effecting function of value is present.

func (Option[T])Get

func (oOption[T]) Get() (T,bool)

Get returns value and presence.Play:https://go.dev/play/p/0-JBa1usZRT

func (*Option[T])GobDecodeadded inv1.4.0

func (o *Option[T]) GobDecode(data []byte)error

GobDecode implements the gob.GobDecoder interface.

func (Option[T])GobEncodeadded inv1.4.0

func (oOption[T]) GobEncode() ([]byte,error)

GobEncode implements the gob.GobEncoder interface.

func (Option[T])IsAbsent

func (oOption[T]) IsAbsent()bool

IsAbsent returns false when value is present.Play:https://go.dev/play/p/23e2zqyVOQm

func (Option[T])IsPresent

func (oOption[T]) IsPresent()bool

IsPresent returns false when value is absent.Play:https://go.dev/play/p/nDqIaiihyCA

func (Option[T])Map

func (oOption[T]) Map(mapper func(value T) (T,bool))Option[T]

Map executes the mapper function if value is present or returns None if absent.Play:https://go.dev/play/p/mvfP3pcP_eJ

func (Option[T])MapNone

func (oOption[T]) MapNone(mapper func() (T,bool))Option[T]

MapNone executes the mapper function if value is absent or returns Option.Play:https://go.dev/play/p/_KaHWZ6Q17b

func (Option[T])MarshalBinaryadded inv1.4.0

func (oOption[T]) MarshalBinary() ([]byte,error)

MarshalBinary is the interface implemented by an object that can marshal itself into a binary form.

func (Option[T])MarshalJSONadded inv1.3.0

func (oOption[T]) MarshalJSON() ([]byte,error)

MarshalJSON encodes Option into json.

func (Option[T])MarshalTextadded inv1.4.0

func (oOption[T]) MarshalText() ([]byte,error)

MarshalText implements the encoding.TextMarshaler interface.

func (Option[T])Match

func (oOption[T]) Match(onValue func(value T) (T,bool), onNone func() (T,bool))Option[T]

Match executes the first function if value is present and second function if absent.It returns a new Option.Play:https://go.dev/play/p/1V6st3LDJsM

func (Option[T])MustGet

func (oOption[T]) MustGet() T

MustGet returns value if present or panics instead.Play:https://go.dev/play/p/RVBckjdi5WR

func (Option[T])OrElse

func (oOption[T]) OrElse(fallback T) T

OrElse returns value if present or default value.Play:https://go.dev/play/p/TrGByFWCzXS

func (Option[T])OrEmpty

func (oOption[T]) OrEmpty() T

OrEmpty returns value if present or empty value.Play:https://go.dev/play/p/SpSUJcE-tQm

func (*Option[T])Scanadded inv1.4.0

func (o *Option[T]) Scan(srcany)error

Scan implements the SQL sql.Scanner interface.

func (Option[T])Size

func (oOption[T]) Size()int

Size returns 1 when value is present or 0 instead.Play:https://go.dev/play/p/7ixCNG1E9l7

func (Option[T])ToPointeradded inv1.10.0

func (oOption[T]) ToPointer() *T

ToPointer returns value if present or a nil pointer.Play:https://go.dev/play/p/N43w92SM-Bs

func (*Option[T])UnmarshalBinaryadded inv1.4.0

func (o *Option[T]) UnmarshalBinary(data []byte)error

UnmarshalBinary is the interface implemented by an object that can unmarshal a binary representation of itself.

func (*Option[T])UnmarshalJSONadded inv1.3.0

func (o *Option[T]) UnmarshalJSON(b []byte)error

UnmarshalJSON decodes Option from json.

func (*Option[T])UnmarshalTextadded inv1.4.0

func (o *Option[T]) UnmarshalText(data []byte)error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Option[T])Valueadded inv1.4.0

func (oOption[T]) Value() (driver.Value,error)

Value implements the driver Valuer interface.

typeResult

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

Result represents a result of an action having oneof the following output: success or failure.An instance of Result is an instance of either Ok or Err.It could be compared to `Either[error, T]`.

funcDoadded inv1.12.0

func Do[Tany](fn func() T) (resultResult[T])

Do executes a function within a monadic context, capturing any errors that occur.If the function executes successfully, its result is wrapped in a successful Result.If the function panics (indicating a failure), the panic is caught and converted into an error Result.

funcErr

func Err[Tany](errerror)Result[T]

Err builds a Result when value is invalid.Play:https://go.dev/play/p/PDwADdzNoyZ

funcErrfadded inv1.10.0

func Errf[Tany](formatstring, a ...any)Result[T]

Errf builds a Result when value is invalid.Errf formats according to a format specifier and returns the error as a value that satisfies Result[T].Play:https://go.dev/play/p/N43w92SM-Bs

funcOk

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

Ok builds a Result when value is valid.Play:https://go.dev/play/p/PDwADdzNoyZ

funcTryadded inv1.1.0

func Try[Tany](f func() (T,error))Result[T]

Try returns either a Ok or Err object.Play:https://go.dev/play/p/ilOlQx-Mx42

funcTupleToResult

func TupleToResult[Tany](value T, errerror)Result[T]

TupleToResult convert a pair of T and error into a Result.Play:https://go.dev/play/p/KWjfqQDHQwa

func (Result[T])Error

func (rResult[T]) Error()error

Error returns error when value is invalid or nil.Play:https://go.dev/play/p/CSkHGTyiXJ5

func (Result[T])FlatMap

func (rResult[T]) FlatMap(mapper func(value T)Result[T])Result[T]

FlatMap executes the mapper function if Result is valid. It returns a new Result.Play:https://go.dev/play/p/Ud5QjZOqg-7

func (Result[T])ForEach

func (rResult[T]) ForEach(mapper func(value T))

ForEach executes the given side-effecting function if Result is valid.

func (Result[T])Get

func (rResult[T]) Get() (T,error)

Get returns value and error.Play:https://go.dev/play/p/8KyX3z6TuNo

func (Result[T])IsError

func (rResult[T]) IsError()bool

IsError returns true when value is invalid.Play:https://go.dev/play/p/xkV9d464scV

func (Result[T])IsOk

func (rResult[T]) IsOk()bool

IsOk returns true when value is valid.Play:https://go.dev/play/p/sfNvBQyZfgU

func (Result[T])Map

func (rResult[T]) Map(mapper func(value T) (T,error))Result[T]

Map executes the mapper function if Result is valid. It returns a new Result.Play:https://go.dev/play/p/-ndpN_b_OSc

func (Result[T])MapErr

func (rResult[T]) MapErr(mapper func(error) (T,error))Result[T]

MapErr executes the mapper function if Result is invalid. It returns a new Result.Play:https://go.dev/play/p/WraZixg9GGf

func (Result[T])MarshalJSONadded inv1.11.0

func (oResult[T]) MarshalJSON() ([]byte,error)

MarshalJSON encodes Result into json, following the JSON-RPC specification for results,with one exception: when the result is an error, the "code" field is not included.Reference:https://www.jsonrpc.org/specification

func (Result[T])Match

func (rResult[T]) Match(onSuccess func(value T) (T,error), onError func(errerror) (T,error))Result[T]

Match executes the first function if Result is valid and second function if invalid.It returns a new Result.Play:https://go.dev/play/p/-_eFaLJ31co

func (Result[T])MustGet

func (rResult[T]) MustGet() T

MustGet returns value when Result is valid or panics.Play:https://go.dev/play/p/8LSlndHoTAE

func (Result[T])OrElse

func (rResult[T]) OrElse(fallback T) T

OrElse returns value when Result is valid or default value.Play:https://go.dev/play/p/MN_ULx0soi6

func (Result[T])OrEmpty

func (rResult[T]) OrEmpty() T

OrEmpty returns value when Result is valid or empty value.Play:https://go.dev/play/p/rdKtBmOcMLh

func (Result[T])ToEither

func (rResult[T]) ToEither()Either[error, T]

ToEither transforms a Result into an Either type.Play:https://go.dev/play/p/Uw1Zz6b952q

func (*Result[T])UnmarshalJSONadded inv1.11.0

func (o *Result[T]) UnmarshalJSON(data []byte)error

UnmarshalJSON decodes json into Result. If "error" is set, the result is anErr containing the error message as a generic error object. Otherwise, theresult is an Ok containing the result. If the JSON object contains netiheran error nor a result, the result is an Ok containing an empty value. If theJSON object contains both an error and a result, the result is an Err. Finally,if the JSON object contains an error but is not structured correctly (no messagefield), the unmarshaling fails.

typeState

type State[Sany, Aany] struct {// contains filtered or unexported fields}

State represents a function `(S) -> (A, S)`, where `S` is state, `A` is result.

funcNewState

func NewState[Sany, Aany](f func(state S) (A, S))State[S, A]

funcReturnState

func ReturnState[Sany, Aany](x A)State[S, A]

func (State[S, A])Get

func (sState[S, A]) Get()State[S, S]

Get returns the current state.

func (State[S, A])Modify

func (sState[S, A]) Modify(f func(state S) S)State[S, A]

Modify the state by applying a function to the current state.

func (State[S, A])Put

func (sState[S, A]) Put(state S)State[S, A]

Put set the state.

func (State[S, A])Run

func (sState[S, A]) Run(state S) (A, S)

Run executes a computation in the State monad.

typeTask

type Task[Rany] struct {// contains filtered or unexported fields}

Task represents a non-deterministic asynchronous computation thatcan cause side effects, yields a value of type `R` and never fails.

funcNewTask

func NewTask[Rany](f ff0[R])Task[R]

NewTask instanciates a new Task.

funcNewTaskFromIO

func NewTaskFromIO[Rany](ioIO[R])Task[R]

NewTaskFromIO instanciates a new Task from an existing IO.

func (Task[R])Run

func (tTask[R]) Run() *Future[R]

Run execute the non-deterministic asynchronous computation, with side effect.

typeTask1

type Task1[Rany, Aany] struct {// contains filtered or unexported fields}

Task1 represents a non-deterministic asynchronous computation thatcan cause side effects, yields a value of type `R` and never fails.

funcNewTask1

func NewTask1[Rany, Aany](f ff1[R, A])Task1[R, A]

NewTask1 instanciates a new Task1.

funcNewTaskFromIO1

func NewTaskFromIO1[Rany, Aany](ioIO1[R, A])Task1[R, A]

NewTaskFromIO1 instanciates a new Task1 from an existing IO1.

func (Task1[R, A])Run

func (tTask1[R, A]) Run(a A) *Future[R]

Run execute the non-deterministic asynchronous computation, with side effect.

typeTask2

type Task2[Rany, Aany, Bany] struct {// contains filtered or unexported fields}

Task2 represents a non-deterministic asynchronous computation thatcan cause side effects, yields a value of type `R` and never fails.

funcNewTask2

func NewTask2[Rany, Aany, Bany](f ff2[R, A, B])Task2[R, A, B]

NewTask2 instanciates a new Task2.

funcNewTaskFromIO2

func NewTaskFromIO2[Rany, Aany, Bany](ioIO2[R, A, B])Task2[R, A, B]

NewTaskFromIO2 instanciates a new Task2 from an existing IO2.

func (Task2[R, A, B])Run

func (tTask2[R, A, B]) Run(a A, b B) *Future[R]

Run execute the non-deterministic asynchronous computation, with side effect.

typeTask3

type Task3[Rany, Aany, Bany, Cany] struct {// contains filtered or unexported fields}

Task3 represents a non-deterministic asynchronous computation thatcan cause side effects, yields a value of type `R` and never fails.

funcNewTask3

func NewTask3[Rany, Aany, Bany, Cany](f ff3[R, A, B, C])Task3[R, A, B, C]

NewTask3 instanciates a new Task3.

funcNewTaskFromIO3

func NewTaskFromIO3[Rany, Aany, Bany, Cany](ioIO3[R, A, B, C])Task3[R, A, B, C]

NewTaskFromIO3 instanciates a new Task3 from an existing IO3.

func (Task3[R, A, B, C])Run

func (tTask3[R, A, B, C]) Run(a A, b B, c C) *Future[R]

Run execute the non-deterministic asynchronous computation, with side effect.

typeTask4

type Task4[Rany, Aany, Bany, Cany, Dany] struct {// contains filtered or unexported fields}

Task4 represents a non-deterministic asynchronous computation thatcan cause side effects, yields a value of type `R` and never fails.

funcNewTask4

func NewTask4[Rany, Aany, Bany, Cany, Dany](f ff4[R, A, B, C, D])Task4[R, A, B, C, D]

NewTask4 instanciates a new Task4.

funcNewTaskFromIO4

func NewTaskFromIO4[Rany, Aany, Bany, Cany, Dany](ioIO4[R, A, B, C, D])Task4[R, A, B, C, D]

NewTaskFromIO4 instanciates a new Task4 from an existing IO4.

func (Task4[R, A, B, C, D])Run

func (tTask4[R, A, B, C, D]) Run(a A, b B, c C, d D) *Future[R]

Run execute the non-deterministic asynchronous computation, with side effect.

typeTask5

type Task5[Rany, Aany, Bany, Cany, Dany, Eany] struct {// contains filtered or unexported fields}

Task5 represents a non-deterministic asynchronous computation thatcan cause side effects, yields a value of type `R` and never fails.

funcNewTask5

func NewTask5[Rany, Aany, Bany, Cany, Dany, Eany](f ff5[R, A, B, C, D, E])Task5[R, A, B, C, D, E]

NewTask5 instanciates a new Task5.

funcNewTaskFromIO5

func NewTaskFromIO5[Rany, Aany, Bany, Cany, Dany, Eany](ioIO5[R, A, B, C, D, E])Task5[R, A, B, C, D, E]

NewTaskFromIO5 instanciates a new Task5 from an existing IO5.

func (Task5[R, A, B, C, D, E])Run

func (tTask5[R, A, B, C, D, E]) Run(a A, b B, c C, d D, e E) *Future[R]

Run execute the non-deterministic asynchronous computation, with side effect.

typeTaskEither

type TaskEither[Rany] struct {Task[R]}

TaskEither represents a non-deterministic asynchronous computation thatcan cause side effects, yields a value of type `R` and can fail.

funcNewTaskEither

func NewTaskEither[Rany](f ff0[R])TaskEither[R]

NewTaskEither instanciates a new TaskEither.

funcNewTaskEitherFromIO

func NewTaskEitherFromIO[Rany](ioIO[R])TaskEither[R]

NewTaskEitherFromIO instanciates a new TaskEither from an existing IO.

func (TaskEither[R])Match

func (tTaskEither[R]) Match(onLeft func(error)Either[error, R], onRight func(R)Either[error, R])Either[error, R]

Match executes the first function if task succeeded and second function if task failed.It returns a new Option.

func (TaskEither[R])OrElse

func (tTaskEither[R]) OrElse(fallback R) R

OrElse returns value if task succeeded or default value.

func (TaskEither[R])ToEither

func (tTaskEither[R]) ToEither()Either[error, R]

ToEither converts TaskEither to Either.

func (TaskEither[R])ToTask

func (tTaskEither[R]) ToTask(fallback R)Task[R]

ToTask converts TaskEither to Task

func (TaskEither[R])TryCatch

func (tTaskEither[R]) TryCatch(onLeft func(error)Either[error, R], onRight func(R)Either[error, R])Either[error, R]

TryCatch is an alias to Match

Source Files

View all Source files

Directories

PathSynopsis
Package options provides cross type transformations for `mo.Option`.
Package options provides cross type transformations for `mo.Option`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp