opt

package
v0.0.88 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2024 License: CC0-1.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoneGet = errors.New("none.Get")

Functions

func Fold added in v0.0.29

func Fold[A, B any](o Option[A], m funcs.Mapper[A, B], f0 funcs.Function0[B]) B

Types

type FMapper added in v0.0.25

type FMapper[T, V any] funcs.Mapper[T, Option[V]]

type Option

type Option[T any] interface {
	IsDefined() bool
	IsEmpty() bool
	Get() (T, error)
	OrElse(other T) T
	OrDefault() T
	ToSlice() []T
	Filter(p funcs.Predicate[T]) Option[T]
	Foreach(p funcs.Procedure[T]) Option[T]

	// Map method can't change the category; see Map function for that matter.
	Map(mapper funcs.Mapper[T, T]) Option[T]
	// FlatMap method can't change the category; see FlatMap function for that matter.
	FlatMap(mapper FMapper[T, T]) Option[T]
}

Option represents the simplest monad that can contain some value, available for mapping with Map,

or nothing (none).

With that said, Map mapper will never face nil.

func FlatMap

func FlatMap[T, V any](m Option[T], f FMapper[T, V]) Option[V]

func Map

func Map[T, V any](m Option[T], f funcs.Mapper[T, V]) Option[V]

func None

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

func OfPtr

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

func Some

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

Jump to

Keyboard shortcuts

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