Documentation
¶
Index ¶
- type Option
- func (o Option[T]) FlatMap(mapper func(value T) Option[T]) Option[T]
- func (o Option[T]) ForEach(onValue func(value T))
- func (o Option[T]) Get() (T, bool)
- func (o Option[T]) Map(mapper func(value T) (T, bool)) Option[T]
- func (o Option[T]) MapNone(mapper func() (T, bool)) Option[T]
- func (o Option[T]) Match(onValue func(value T) (T, bool), onNone func() (T, bool)) Option[T]
- func (o Option[T]) MustGet() T
- func (o Option[T]) None() bool
- func (o Option[T]) OrElse(fallback T) T
- func (o Option[T]) OrEmpty() T
- func (o Option[T]) Some() bool
- func (o Option[T]) ToPointer() *T
- type Result
- func (r Result[T]) Error() error
- func (r Result[T]) FlatMap(mapper func(value T) Result[T]) Result[T]
- func (r Result[T]) ForEach(mapper func(value T))
- func (r Result[T]) Get() (T, error)
- func (r Result[T]) Map(mapper func(value T) (T, error)) Result[T]
- func (r Result[T]) MapErr(mapper func(error) (T, error)) Result[T]
- func (r Result[T]) Match(onSuccess func(value T) (T, error), onError func(err error) (T, error)) Result[T]
- func (r Result[T]) MustGet() T
- func (r Result[T]) Ok() bool
- func (r Result[T]) OrElse(fallback T) T
- func (r Result[T]) OrEmpty() T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option[T any] struct { // contains filtered or unexported fields }
Option is a container for an optional value of type T. If value exists, Option is of type Some. If the value is absent, Option is of type None.
func EmptyableToOption ¶
EmptyableToOption builds a Some Option when value is not empty, or None.
func PointerToOption ¶
PointerToOption builds a Some Option when value is not nil, or None.
func TupleToOption ¶
TupleToOption builds a Some Option when second argument is true, or None.
func (Option[T]) FlatMap ¶
FlatMap executes the mapper function if value is present or returns None if absent.
func (Option[T]) ForEach ¶
func (o Option[T]) ForEach(onValue func(value T))
ForEach executes the given side-effecting function of value is present.
func (Option[T]) Map ¶
Map executes the mapper function if value is present or returns None if absent.
func (Option[T]) MapNone ¶
MapNone executes the mapper function if value is absent or returns Option. Play: https://go.dev/play/p/_KaHWZ6Q17b
func (Option[T]) Match ¶
Match executes the first function if value is present and second function if absent. It returns a new Option.
func (Option[T]) MustGet ¶
func (o Option[T]) MustGet() T
MustGet returns value if present or panics instead. Play: https://go.dev/play/p/RVBckjdi5WR
func (Option[T]) OrElse ¶
func (o Option[T]) OrElse(fallback T) T
OrElse returns value if present or default value.
func (Option[T]) OrEmpty ¶
func (o Option[T]) OrEmpty() T
OrEmpty returns value if present or empty value.
func (Option[T]) ToPointer ¶
func (o Option[T]) ToPointer() *T
ToPointer returns value if present or a nil pointer. Play: https://go.dev/play/p/N43w92SM-Bs
type Result ¶
type Result[T any] struct { // contains filtered or unexported fields }
Result represents a result of an action having one of the following output: success or failure. An instance of Result is an instance of either Ok or Err.
func Errf ¶
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].
func TupleToResult ¶
TupleToResult convert a pair of T and error into a Result. Play: https://go.dev/play/p/KWjfqQDHQwa
func (Result[T]) FlatMap ¶
FlatMap executes the mapper function if Result is valid. It returns a new Result.
func (Result[T]) ForEach ¶
func (r Result[T]) ForEach(mapper func(value T))
ForEach executes the given side-effecting function if Result is valid.
func (Result[T]) Map ¶
Map executes the mapper function if Result is valid. It returns a new Result.
func (Result[T]) MapErr ¶
MapErr executes the mapper function if Result is invalid. It returns a new Result.
func (Result[T]) Match ¶
func (r Result[T]) Match(onSuccess func(value T) (T, error), onError func(err error) (T, error)) Result[T]
Match executes the first function if Result is valid and second function if invalid. It returns a new Result.
func (Result[T]) MustGet ¶
func (r Result[T]) MustGet() T
MustGet returns value when Result is valid or panics.