option

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 0 Imported by: 3

Documentation

Overview

Package option implements optional values to represent the lack of value without pointers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNil

func IsNil[T any](opt Of[T]) bool

IsNil returns true if the value is nil.

func UnwrapOrZero

func UnwrapOrZero[T any](opt Of[T]) T

UnwrapOrZero returns the option value or its zero value if it is not set.

Types

type Of

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

Of represents an optional value that may be nil.

func Map

func Map[T, U any](opt Of[T], f func(T) U) Of[U]

Map applies function f to the underlying option value if it is set.

func Nil

func Nil[T any]() Of[T]

Nil returns nil option with type T.

func Value

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

Value returns an option with the given value.

func (Of[T]) Unwrap

func (v Of[T]) Unwrap() (T, bool)

Unwrap returns the underlying value and a boolean flag indicating whether it is set.

Jump to

Keyboard shortcuts

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