Documentation ¶
Index ¶
- type Maybe
- func (m Maybe[T]) Filter(predicate func(T) bool) Maybe[T]
- func (m Maybe[T]) FilterNotNil() Maybe[T]
- func (m Maybe[T]) Get() (T, bool)
- func (m Maybe[T]) IfPresent(consume func(T)) Maybe[T]
- func (m Maybe[T]) IfPresentOrElse(consume func(T), els func()) Maybe[T]
- func (m Maybe[T]) IsEmpty() bool
- func (m Maybe[T]) IsPresent() bool
- func (m Maybe[T]) MapToAny(mapper func(T) any) Maybe[any]
- func (m Maybe[T]) MapToFloat32(mapper func(T) float32) Maybe[float32]
- func (m Maybe[T]) MapToFloat64(mapper func(T) float64) Maybe[float64]
- func (m Maybe[T]) MapToInt(mapper func(T) int) Maybe[int]
- func (m Maybe[T]) MapToInt16(mapper func(T) int16) Maybe[int16]
- func (m Maybe[T]) MapToInt32(mapper func(T) int32) Maybe[int32]
- func (m Maybe[T]) MapToInt64(mapper func(T) int64) Maybe[int64]
- func (m Maybe[T]) MapToString(mapper func(T) string) Maybe[string]
- func (m Maybe[T]) MapToUint(mapper func(T) uint) Maybe[uint]
- func (m Maybe[T]) MapToUint16(mapper func(T) uint16) Maybe[uint16]
- func (m Maybe[T]) MapToUint32(mapper func(T) uint32) Maybe[uint32]
- func (m Maybe[T]) MapToUint64(mapper func(T) uint64) Maybe[uint64]
- func (m Maybe[T]) Or(supply func() Maybe[T]) Maybe[T]
- func (m Maybe[T]) OrElse(other T) T
- func (m Maybe[T]) OrElseGet(supply func() T) T
- func (m Maybe[T]) Value() T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Maybe ¶
type Maybe[T any] struct { // contains filtered or unexported fields }
Maybe is generic monadic container for value or it's absence
func Just ¶
Just constructs new Maybe with given value. This constructor will create non-empty Maybe even for nil value, for protection use Nilable instead.
func Nilable ¶
Nilable constructs new Maybe and performs emptiness check of given data. Will produce empty Maybe for following cases: - nil value - zero-length slice - zero-length map
func (Maybe[T]) Filter ¶
Filter applies given predicate of container returning original value only if predicate resulted in true.
func (Maybe[T]) FilterNotNil ¶
FilterNotNil filters Maybe leaving only non-nil value.
func (Maybe[T]) IfPresentOrElse ¶
IfPresent invokes given consumer callback if value present and plain func if container empty.
func (Maybe[T]) MapToFloat32 ¶
func (Maybe[T]) MapToFloat64 ¶
func (Maybe[T]) Or ¶
Or produces Maybe: 1. If current not empty - return it 2. If current is empty - return produced by supply func 3. Nothing if current is empty and supply function is nil
func (Maybe[T]) OrElse ¶
func (m Maybe[T]) OrElse(other T) T
OrElse returns value from Maybe if it presents, otherwise given value is returned.