optional

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2023 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 ComparableOptional added in v0.3.0

type ComparableOptional[T comparable] struct {
	Optional[T]
}

func (ComparableOptional[T]) Eq added in v0.3.0

func (self ComparableOptional[T]) Eq(other ComparableOptional[T]) bool

func (ComparableOptional[T]) Ne added in v0.3.0

func (self ComparableOptional[T]) Ne(other ComparableOptional[T]) bool

type FlattenOptional added in v0.3.0

type FlattenOptional[T any] struct {
	Optional[Optional[T]]
}

func (FlattenOptional[T]) Flatten added in v0.3.0

func (self FlattenOptional[T]) Flatten() Optional[T]

type Optional

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

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

func As added in v0.3.0

func As[T any](v any) Optional[T]

func FromPair added in v0.3.0

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

FromPair returns an Optional from a value.

func FromPtr added in v0.3.0

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

FromPtr 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 Some

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

Some returns an Optional from a value. Oops!! We can't restrict T is not pointer type. Holy shit!!!

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]) CloneBy added in v0.3.0

func (self Optional[T]) CloneBy(clone func(T) T) Optional[T]

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]) MarshalJSON added in v0.3.0

func (self Optional[T]) MarshalJSON() ([]byte, error)

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]) UnmarshalJSON added in v0.3.0

func (self *Optional[T]) UnmarshalJSON(v []byte) error

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