optional

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Optional

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

Optional is a value that may or may not be present.

func Clone

func Clone[T clone.Cloneable[T]](opt Optional[T]) Optional[T]

func From

func From[T any](data T, ok bool) Optional[T]

From returns an Optional from a value.

func Map

func Map[A, B any](opt Optional[A], mapFn func(A) B) Optional[B]

func None

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

None returns an Optional from a value.

func Of

func Of[T any](data *T) Optional[T]

Of returns an Optional from a value.

func Some

func Some[T any](data T) Optional[T]

Some returns an Optional from a value.

func (Optional[T]) And

func (self Optional[T]) And(opt Optional[T]) Optional[T]

And returns None if the option is None, otherwise returns given opt.

func (Optional[T]) AndThen added in v0.2.0

func (self Optional[T]) AndThen(f func(T) Optional[T]) Optional[T]

AndThen returns None if the option is None, otherwise calls f with the wrapped value and returns the result.

func (Optional[T]) Filter

func (self Optional[T]) Filter(fn func(T) bool) Optional[T]

func (Optional[T]) IfPresent

func (self Optional[T]) IfPresent(consume func(T))

func (Optional[T]) IsNone

func (self Optional[T]) IsNone() bool

IsNone returns true if the Optional is None.

func (Optional[T]) IsSome

func (self Optional[T]) IsSome() bool

IsSome returns true if the Optional is Some.

func (Optional[T]) IsSomeAnd added in v0.2.0

func (self Optional[T]) IsSomeAnd(predicate func(T) bool) bool

IsSomeAnd returns true if the Optional is Some and satisfies the given predicate.

func (Optional[T]) Map

func (self Optional[T]) Map(f func(T) T) Optional[T]

Map returns None if the option is None, otherwise calls the given function and returns the result.

func (Optional[T]) MapOr added in v0.2.0

func (self Optional[T]) MapOr(defaultValue T, f func(T) T) T

MapOr returns None if the option is None, otherwise calls the given function and returns the result.

func (Optional[T]) MapOrElse added in v0.2.0

func (self Optional[T]) MapOrElse(df func() T, f func(T) T) T

MapOrElse returns None if the option is None, otherwise calls the given function and returns the result.

func (Optional[T]) Or

func (self Optional[T]) Or(opt Optional[T]) Optional[T]

Or returns the given opt if the option is None, otherwise returns the option.

func (Optional[T]) OrElse

func (self Optional[T]) OrElse(f func() Optional[T]) Optional[T]

OrElse returns the Optional if it contains a value, otherwise calls f and returns the result.

func (Optional[T]) String added in v0.1.1

func (self Optional[T]) String() string

func (Optional[T]) Value

func (self Optional[T]) Value() T

Value returns the value of the Optional.

func (Optional[T]) ValueOr added in v0.2.0

func (self Optional[T]) ValueOr(defaultValue T) T

ValueOr returns the Optional if it is Some, otherwise returns the given default value.

func (Optional[T]) ValueOrElse added in v0.2.0

func (self Optional[T]) ValueOrElse(defaultFunc func() T) T

ValueOrElse returns the Optional if it is Some, otherwise returns the given default value.

func (Optional[T]) ValueOrZero added in v0.2.0

func (self Optional[T]) ValueOrZero() T

ValueOrZero returns the Optional if it is Some, otherwise returns the zero value of the type.

func (Optional[T]) Xor added in v0.2.0

func (self Optional[T]) Xor(opt Optional[T]) Optional[T]

Xor returns None if the option is None, otherwise returns the given opt.

Jump to

Keyboard shortcuts

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