maybe

package
v1.13.4-lux.18-chain Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2025 License: BSD-3-Clause Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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