maybe

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package maybe implements a maybe type, also known as an option(al) type.

We use the "maybe" terminology so as to avoid confusion with the "optional" and "required" types used to represent environment variable values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Value

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

Value is an optional value of type T.

func Map

func Map[T, U any](m Value[T], fn func(T) U) Value[U]

Map converts m to a maybe-value of type U by applying a mapping function.

func None

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

None returns an empty value.

func Some

func Some[T any](v T) Value[T]

Some returns a non-empty value.

func TryMap

func TryMap[T, U any](m Value[T], fn func(T) (U, error)) (Value[U], error)

TryMap converts m to a maybe-value of type U by applying a mapping function.

func (Value[T]) Get

func (m Value[T]) Get() (v T, ok bool)

Get returns the optional value.

If m is empty ok is false; otherwise, ok is true and v is the value.

func (Value[T]) IsEmpty

func (m Value[T]) IsEmpty() bool

IsEmpty returns true if m is empty, meaning that it does not have a value.

func (Value[T]) MustGet

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

MustGet returns the optional value or panics if m is empty.

Jump to

Keyboard shortcuts

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