options

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package options implements simple functions to manipulate optional values.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotPresent = errors.New("value not present")
	ErrNotOk      = errors.New("value not ok")
)

Functions

func Must

func Must[T any](value T, ok bool) T

func OrElse

func OrElse[T any](ok bool, value T, other T) T

Types

type Option

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

func Empty

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

func From

func From[T any](value T, isPresent bool) Option[T]

func FromPointer added in v0.3.0

func FromPointer[T any](pointer *T) Option[T]

func Some

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

func (Option[T]) Get

func (o Option[T]) Get() T

func (Option[T]) IsPresent

func (o Option[T]) IsPresent() bool

func (Option[T]) OrElse

func (o Option[T]) OrElse(other T) T

func (Option[T]) OrEmpty

func (o Option[T]) OrEmpty() T

Jump to

Keyboard shortcuts

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