result

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package result implements the Result type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func After

func After[A any](dur time.Duration, a A) warp.Result[A]

func Ap

func Ap[A, B any](fab warp.Result[func(A) B], fa warp.Result[A]) warp.Result[B]

Ap creates a result by applying a function contained in the first result on the value contained in the second result.

func ApFirst

func ApFirst[A, B any](fa warp.Result[A], fb warp.Result[B]) warp.Result[A]

ApFirst creates a result by combining two effectful computations, keeping only the result of the first.

func ApSecond

func ApSecond[A, B any](fa warp.Result[A], fb warp.Result[B]) warp.Result[B]

ApSecond creates a result by combining two effectful computations, keeping only the result of the second.

func Bimap

func Bimap[A, B any](fa warp.Result[A], f func(error) error, g func(A) B) warp.Result[B]

Bimap creates a result by mapping a pair of functions over an error or a value contained in a result.

func Chain

func Chain[A, B any](ma warp.Result[A], f func(A) warp.Result[B]) warp.Result[B]

Chain creates a result which combines two results in sequence, using the return value of one result to determine the next one.

func ChainFirst

func ChainFirst[A, B any](ma warp.Result[A], f func(A) warp.Result[B]) warp.Result[A]

ChainFirst composes two results in sequence, using the return value of one result to determine the next one, keeping only the first result.

func Error

func Error[A any](err error) warp.Result[A]

Error creates a result which always fails with an error.

func ErrorAfter

func ErrorAfter[A any](dur time.Duration, err error) warp.Result[A]

func FilterOrElse

func FilterOrElse[A any](ma warp.Result[A], predicate warp.Predicate[A], onFalse func(A) error) warp.Result[A]

FilterOrElse creates a result which can be used to fail with an error unless a predicate holds on a succeeding result.

func Fork

func Fork[A any](ctx context.Context, ma warp.Result[A], onError func(error), onSuccess func(A))

Fork is like Reduce but it doesn't have a return value.

func FromNilable

func FromNilable[A any](ma warp.Nilable[A], onNil func() error) warp.Result[A]

FromNilable creates a result from a nilable, returning the supplied error for nil values.

func FromResult

func FromResult[A any](result warp.Result[A]) (r warp.Result[A])

func FromResult1

func FromResult1[A, I any](f func(context.Context, I) (A, error), i I) warp.Result[A]

func GetOrElse

func GetOrElse[A any](ctx context.Context, ma warp.Result[A], onError func(error) A) A

GetOrElse creates a result which can be used to recover from a failing result with a new value.

func Map

func Map[A, B any](fa warp.Result[A], f func(A) B) warp.Result[B]

Map creates a result by applying a function on a succeeding result.

func MapError

func MapError[A any](fa warp.Result[A], f func(error) error) warp.Result[A]

MapError creates a result by applying a function on a failing result.

func Ok

func Ok[A any](a A) warp.Result[A]

Ok creates a result which never fails and returns a value of type A.

func OrElse

func OrElse[A any](ma warp.Result[A], onError func(error) warp.Result[A]) warp.Result[A]

OrElse creates a result which can be used to recover from a failing result by switching to a new result.

func Reduce

func Reduce[A, B any](ctx context.Context, ma warp.Result[A], onError func(error) B, onSuccess func(A) B) B

Reduce takes two functions and a result and returns a value by applying one of the supplied functions to the inner value.

func Zero

func Zero[A any]() warp.Result[A]

Zero creates a result which never fails and returns a zero value of the type that it is initialized with.

Types

This section is empty.

Jump to

Keyboard shortcuts

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