maybe

package
v1.10.18-rc.15 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: BSD-3-Clause Imports: 1 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal[T any](m1 Maybe[T], m2 Maybe[T], equalFunc func(T, T) bool) bool

Equal returns true if both m1 and m2 are nothing or have the same value according to [equalFunc].

Types

type Maybe

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

Maybe T = Some T | Nothing. A data wrapper that allows values to be something [Some T] or nothing Nothing. Invariant: If [hasValue] is false, then [value] is the zero value of type T. Maybe is used to wrap types: * That can't be represented by nil. * That use nil as a valid value instead of an indicator of a missing value. For more info see https://en.wikipedia.org/wiki/Option_type

func Bind

func Bind[T, U any](m Maybe[T], f func(T) U) Maybe[U]

Bind returns Nothing iff [m] is Nothing. Otherwise applies [f] to the value of [m] and returns the result as a Some.

func Nothing

func Nothing[T any]() Maybe[T]

Nothing returns a new Maybe[T] with no value.

func Some

func Some[T any](val T) Maybe[T]

Some returns a new Maybe[T] with the value val. If m.IsNothing(), returns the zero value of type T.

func (Maybe[T]) HasValue

func (m Maybe[T]) HasValue() bool

HasValue returns true iff [m] has a value.

func (Maybe[T]) IsNothing

func (m Maybe[T]) IsNothing() bool

IsNothing returns false iff [m] has a value.

func (Maybe[T]) String added in v1.10.9

func (m Maybe[T]) String() string

func (Maybe[T]) Value

func (m Maybe[T]) Value() T

Value returns the value of [m].

Jump to

Keyboard shortcuts

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