Documentation ¶
Overview ¶
Package option defines the Option datastructure and its monadic operations
package option implements the Option monad, a data type that can have a defined value or none
Index ¶
- func Alt[A any](that func() Option[A]) func(Option[A]) Option[A]
- func AltMonoid[A any]() M.Monoid[Option[A]]
- func AlternativeMonoid[A any](m M.Monoid[A]) M.Monoid[Option[A]]
- func Ap[B, A any](fa Option[A]) func(Option[func(A) B]) Option[B]
- func ApS[S1, S2, T any](setter func(T) func(S1) S2, fa Option[T]) func(Option[S1]) Option[S2]
- func ApplicativeMonoid[A any](m M.Monoid[A]) M.Monoid[Option[A]]
- func ApplySemigroup[A any](s S.Semigroup[A]) S.Semigroup[Option[A]]
- func Bind[S1, S2, A any](setter func(A) func(S1) S2, f func(S1) Option[A]) func(Option[S1]) Option[S2]
- func BindTo[S1, T any](setter func(T) S1) func(Option[T]) Option[S1]
- func Chain[A, B any](f func(A) Option[B]) func(Option[A]) Option[B]
- func ChainFirst[A, B any](f func(A) Option[B]) func(Option[A]) Option[A]
- func ChainTo[A, B any](mb Option[B]) func(Option[A]) Option[B]
- func CompactArray[A any](fa []Option[A]) []A
- func CompactArrayG[A1 ~[]Option[A], A2 ~[]A, A any](fa A1) A2
- func CompactRecord[K comparable, A any](m map[K]Option[A]) map[K]A
- func CompactRecordG[M1 ~map[K]Option[A], M2 ~map[K]A, K comparable, A any](m M1) M2
- func Eq[A any](a EQ.Eq[A]) EQ.Eq[Option[A]]
- func Filter[A any](pred func(A) bool) func(Option[A]) Option[A]
- func Flap[B, A any](a A) func(Option[func(A) B]) Option[B]
- func Fold[A, B any](onNone func() B, onSome func(a A) B) func(ma Option[A]) B
- func FromPredicate[A any](pred func(A) bool) func(A) Option[A]
- func FromStrictCompare[A C.Ordered]() ord.Ord[Option[A]]
- func FromStrictEquals[A comparable]() EQ.Eq[Option[A]]
- func FromValidation[A, B any](f func(A) (B, bool)) func(A) Option[B]
- func Functor[A, B any]() functor.Functor[A, B, Option[A], Option[B]]
- func GetOrElse[A any](onNone func() A) func(Option[A]) A
- func IsNone[T any](val Option[T]) bool
- func IsSome[T any](val Option[T]) bool
- func Let[S1, S2, B any](key func(B) func(S1) S2, f func(S1) B) func(Option[S1]) Option[S2]
- func LetTo[S1, S2, B any](key func(B) func(S1) S2, b B) func(Option[S1]) Option[S2]
- func Logger[A any](loggers ...*log.Logger) func(string) func(Option[A]) Option[A]
- func Map[A, B any](f func(a A) B) func(Option[A]) Option[B]
- func MapTo[A, B any](b B) func(Option[A]) Option[B]
- func Monad[A, B any]() monad.Monad[A, B, Option[A], Option[B], Option[func(A) B]]
- func MonadFold[A, B any](ma Option[A], onNone func() B, onSome func(A) B) B
- func MonadGetOrElse[A any](fa Option[A], onNone func() A) A
- func Monoid[A any]() func(S.Semigroup[A]) M.Monoid[Option[A]]
- func Optionize0[F ~func() (R, bool), R any](f F) func() Option[R]
- func Optionize1[F ~func(T0) (R, bool), T0, R any](f F) func(T0) Option[R]
- func Optionize10[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) (R, bool), ...](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) Option[R]
- func Optionize2[F ~func(T0, T1) (R, bool), T0, T1, R any](f F) func(T0, T1) Option[R]
- func Optionize3[F ~func(T0, T1, T2) (R, bool), T0, T1, T2, R any](f F) func(T0, T1, T2) Option[R]
- func Optionize4[F ~func(T0, T1, T2, T3) (R, bool), T0, T1, T2, T3, R any](f F) func(T0, T1, T2, T3) Option[R]
- func Optionize5[F ~func(T0, T1, T2, T3, T4) (R, bool), T0, T1, T2, T3, T4, R any](f F) func(T0, T1, T2, T3, T4) Option[R]
- func Optionize6[F ~func(T0, T1, T2, T3, T4, T5) (R, bool), T0, T1, T2, T3, T4, T5, R any](f F) func(T0, T1, T2, T3, T4, T5) Option[R]
- func Optionize7[F ~func(T0, T1, T2, T3, T4, T5, T6) (R, bool), ...](f F) func(T0, T1, T2, T3, T4, T5, T6) Option[R]
- func Optionize8[F ~func(T0, T1, T2, T3, T4, T5, T6, T7) (R, bool), ...](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) Option[R]
- func Optionize9[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8) (R, bool), ...](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8) Option[R]
- func Ord[A any](a ord.Ord[A]) ord.Ord[Option[A]]
- func Pointed[A any]() pointed.Pointed[A, Option[A]]
- func Reduce[A, B any](f func(B, A) B, initial B) func(Option[A]) B
- func Semigroup[A any]() func(S.Semigroup[A]) S.Semigroup[Option[A]]
- func Sequence[A, HKTA, HKTOA any](mof func(Option[A]) HKTOA, mmap func(func(A) Option[A]) func(HKTA) HKTOA) func(Option[HKTA]) HKTOA
- func Sequence2[T1, T2, R any](f func(T1, T2) Option[R]) func(Option[T1], Option[T2]) Option[R]
- func Traverse[A, B, HKTB, HKTOB any](mof func(Option[B]) HKTOB, mmap func(func(B) Option[B]) func(HKTB) HKTOB) func(func(A) HKTB) func(Option[A]) HKTOB
- func TraverseArray[A, B any](f func(A) Option[B]) func([]A) Option[[]B]
- func TraverseArrayG[GA ~[]A, GB ~[]B, A, B any](f func(A) Option[B]) func(GA) Option[GB]
- func TraverseArrayWithIndex[A, B any](f func(int, A) Option[B]) func([]A) Option[[]B]
- func TraverseArrayWithIndexG[GA ~[]A, GB ~[]B, A, B any](f func(int, A) Option[B]) func(GA) Option[GB]
- func TraverseRecord[K comparable, A, B any](f func(A) Option[B]) func(map[K]A) Option[map[K]B]
- func TraverseRecordG[GA ~map[K]A, GB ~map[K]B, K comparable, A, B any](f func(A) Option[B]) func(GA) Option[GB]
- func TraverseRecordWithIndex[K comparable, A, B any](f func(K, A) Option[B]) func(map[K]A) Option[map[K]B]
- func TraverseRecordWithIndexG[GA ~map[K]A, GB ~map[K]B, K comparable, A, B any](f func(K, A) Option[B]) func(GA) Option[GB]
- func TraverseTuple1[F1 ~func(A1) Option[T1], A1, T1 any](f1 F1) func(T.Tuple1[A1]) Option[T.Tuple1[T1]]
- func TraverseTuple10[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], ...](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9, f10 F10) ...
- func TraverseTuple2[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], A1, T1, A2, T2 any](f1 F1, f2 F2) func(T.Tuple2[A1, A2]) Option[T.Tuple2[T1, T2]]
- func TraverseTuple3[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], ...](f1 F1, f2 F2, f3 F3) func(T.Tuple3[A1, A2, A3]) Option[T.Tuple3[T1, T2, T3]]
- func TraverseTuple4[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], ...](f1 F1, f2 F2, f3 F3, f4 F4) func(T.Tuple4[A1, A2, A3, A4]) Option[T.Tuple4[T1, T2, T3, T4]]
- func TraverseTuple5[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], ...](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5) func(T.Tuple5[A1, A2, A3, A4, A5]) Option[T.Tuple5[T1, T2, T3, T4, T5]]
- func TraverseTuple6[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], ...](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6) ...
- func TraverseTuple7[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], ...](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7) ...
- func TraverseTuple8[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], ...](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8) ...
- func TraverseTuple9[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], ...](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9) ...
- func Unoptionize0[F ~func() Option[R], R any](f F) func() (R, bool)
- func Unoptionize1[F ~func(T0) Option[R], T0, R any](f F) func(T0) (R, bool)
- func Unoptionize10[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) Option[R], ...](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) (R, bool)
- func Unoptionize2[F ~func(T0, T1) Option[R], T0, T1, R any](f F) func(T0, T1) (R, bool)
- func Unoptionize3[F ~func(T0, T1, T2) Option[R], T0, T1, T2, R any](f F) func(T0, T1, T2) (R, bool)
- func Unoptionize4[F ~func(T0, T1, T2, T3) Option[R], T0, T1, T2, T3, R any](f F) func(T0, T1, T2, T3) (R, bool)
- func Unoptionize5[F ~func(T0, T1, T2, T3, T4) Option[R], T0, T1, T2, T3, T4, R any](f F) func(T0, T1, T2, T3, T4) (R, bool)
- func Unoptionize6[F ~func(T0, T1, T2, T3, T4, T5) Option[R], T0, T1, T2, T3, T4, T5, R any](f F) func(T0, T1, T2, T3, T4, T5) (R, bool)
- func Unoptionize7[F ~func(T0, T1, T2, T3, T4, T5, T6) Option[R], ...](f F) func(T0, T1, T2, T3, T4, T5, T6) (R, bool)
- func Unoptionize8[F ~func(T0, T1, T2, T3, T4, T5, T6, T7) Option[R], ...](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) (R, bool)
- func Unoptionize9[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8) Option[R], ...](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8) (R, bool)
- func Unwrap[A any](ma Option[A]) (A, bool)
- type Option
- func Do[S any](empty S) Option[S]
- func Flatten[A any](mma Option[Option[A]]) Option[A]
- func FromNillable[A any](a *A) Option[*A]
- func MonadAlt[A any](fa Option[A], that func() Option[A]) Option[A]
- func MonadAp[B, A any](fab Option[func(A) B], fa Option[A]) Option[B]
- func MonadChain[A, B any](fa Option[A], f func(A) Option[B]) Option[B]
- func MonadChainFirst[A, B any](ma Option[A], f func(A) Option[B]) Option[A]
- func MonadChainTo[A, B any](_ Option[A], mb Option[B]) Option[B]
- func MonadFlap[B, A any](fab Option[func(A) B], a A) Option[B]
- func MonadMap[A, B any](fa Option[A], f func(A) B) Option[B]
- func MonadMapTo[A, B any](fa Option[A], b B) Option[B]
- func MonadSequence2[T1, T2, R any](o1 Option[T1], o2 Option[T2], f func(T1, T2) Option[R]) Option[R]
- func None[T any]() Option[T]
- func Of[T any](value T) Option[T]
- func SequenceArray[A any](ma []Option[A]) Option[[]A]
- func SequenceArrayG[GA ~[]A, GOA ~[]Option[A], A any](ma GOA) Option[GA]
- func SequencePair[T1, T2 any](t P.Pair[Option[T1], Option[T2]]) Option[P.Pair[T1, T2]]
- func SequenceRecord[K comparable, A any](ma map[K]Option[A]) Option[map[K]A]
- func SequenceRecordG[GA ~map[K]A, GOA ~map[K]Option[A], K comparable, A any](ma GOA) Option[GA]
- func SequenceT1[T1 any](t1 Option[T1]) Option[T.Tuple1[T1]]
- func SequenceT10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](t1 Option[T1], t2 Option[T2], t3 Option[T3], t4 Option[T4], t5 Option[T5], ...) Option[T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]
- func SequenceT2[T1, T2 any](t1 Option[T1], t2 Option[T2]) Option[T.Tuple2[T1, T2]]
- func SequenceT3[T1, T2, T3 any](t1 Option[T1], t2 Option[T2], t3 Option[T3]) Option[T.Tuple3[T1, T2, T3]]
- func SequenceT4[T1, T2, T3, T4 any](t1 Option[T1], t2 Option[T2], t3 Option[T3], t4 Option[T4]) Option[T.Tuple4[T1, T2, T3, T4]]
- func SequenceT5[T1, T2, T3, T4, T5 any](t1 Option[T1], t2 Option[T2], t3 Option[T3], t4 Option[T4], t5 Option[T5]) Option[T.Tuple5[T1, T2, T3, T4, T5]]
- func SequenceT6[T1, T2, T3, T4, T5, T6 any](t1 Option[T1], t2 Option[T2], t3 Option[T3], t4 Option[T4], t5 Option[T5], ...) Option[T.Tuple6[T1, T2, T3, T4, T5, T6]]
- func SequenceT7[T1, T2, T3, T4, T5, T6, T7 any](t1 Option[T1], t2 Option[T2], t3 Option[T3], t4 Option[T4], t5 Option[T5], ...) Option[T.Tuple7[T1, T2, T3, T4, T5, T6, T7]]
- func SequenceT8[T1, T2, T3, T4, T5, T6, T7, T8 any](t1 Option[T1], t2 Option[T2], t3 Option[T3], t4 Option[T4], t5 Option[T5], ...) Option[T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]
- func SequenceT9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](t1 Option[T1], t2 Option[T2], t3 Option[T3], t4 Option[T4], t5 Option[T5], ...) Option[T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]
- func SequenceTuple1[T1 any](t T.Tuple1[Option[T1]]) Option[T.Tuple1[T1]]
- func SequenceTuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](...) Option[T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]
- func SequenceTuple2[T1, T2 any](t T.Tuple2[Option[T1], Option[T2]]) Option[T.Tuple2[T1, T2]]
- func SequenceTuple3[T1, T2, T3 any](t T.Tuple3[Option[T1], Option[T2], Option[T3]]) Option[T.Tuple3[T1, T2, T3]]
- func SequenceTuple4[T1, T2, T3, T4 any](t T.Tuple4[Option[T1], Option[T2], Option[T3], Option[T4]]) Option[T.Tuple4[T1, T2, T3, T4]]
- func SequenceTuple5[T1, T2, T3, T4, T5 any](t T.Tuple5[Option[T1], Option[T2], Option[T3], Option[T4], Option[T5]]) Option[T.Tuple5[T1, T2, T3, T4, T5]]
- func SequenceTuple6[T1, T2, T3, T4, T5, T6 any](...) Option[T.Tuple6[T1, T2, T3, T4, T5, T6]]
- func SequenceTuple7[T1, T2, T3, T4, T5, T6, T7 any](...) Option[T.Tuple7[T1, T2, T3, T4, T5, T6, T7]]
- func SequenceTuple8[T1, T2, T3, T4, T5, T6, T7, T8 any](...) Option[T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]
- func SequenceTuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](...) Option[T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]
- func Some[T any](value T) Option[T]
- func ToAny[T any](src T) Option[any]
- func ToType[T any](src any) Option[T]
- func TryCatch[A any](f func() (A, error)) Option[A]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AlternativeMonoid ¶ added in v1.0.40
func ApS ¶ added in v1.0.107
ApS attaches a value to a context [S1] to produce a context [S2] by considering the context and the value concurrently
func ApplicativeMonoid ¶
ApplicativeMonoid returns a Monoid that concatenates Option instances via their applicative
func Bind ¶ added in v1.0.107
func Bind[S1, S2, A any]( setter func(A) func(S1) S2, f func(S1) Option[A], ) func(Option[S1]) Option[S2]
Bind attaches the result of a computation to a context [S1] to produce a context [S2]
func CompactArray ¶ added in v1.0.26
CompactArray discards the none values and keeps the some values
func CompactArrayG ¶ added in v1.0.26
CompactArrayG discards the none values and keeps the some values
func CompactRecord ¶ added in v1.0.26
func CompactRecord[K comparable, A any](m map[K]Option[A]) map[K]A
CompactRecord discards the noe values and keeps the some values
func CompactRecordG ¶ added in v1.0.26
func CompactRecordG[M1 ~map[K]Option[A], M2 ~map[K]A, K comparable, A any](m M1) M2
CompactRecordG discards the noe values and keeps the some values
func FromPredicate ¶
func FromStrictCompare ¶ added in v1.0.19
FromStrictCompare constructs an Ord from the canonical comparison function
func FromStrictEquals ¶
func FromStrictEquals[A comparable]() EQ.Eq[Option[A]]
FromStrictEquals constructs an [EQ.Eq] from the canonical comparison function
func FromValidation ¶
func Let ¶ added in v1.0.107
Let attaches the result of a computation to a context [S1] to produce a context [S2]
func LetTo ¶ added in v1.0.107
LetTo attaches the a value to a context [S1] to produce a context [S2]
func MonadGetOrElse ¶ added in v1.0.58
func Monoid ¶
Monoid returning the left-most non-`None` value. If both operands are `Some`s then the inner values are concatenated using the provided `Semigroup`
| x | y | concat(x, y) | | ------- | ------- | ------------------ | | none | none | none | | some(a) | none | some(a) | | none | some(b) | some(b) | | some(a) | some(b) | some(concat(a, b)) |
func Optionize0 ¶
Optionize0 converts a function with 0 parameters returning a tuple of a return value R and a boolean into a function with 0 parameters returning an Option[R]
func Optionize1 ¶
Optionize1 converts a function with 1 parameters returning a tuple of a return value R and a boolean into a function with 1 parameters returning an Option[R]
func Optionize10 ¶
func Optionize10[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) (R, bool), T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) Option[R]
Optionize10 converts a function with 10 parameters returning a tuple of a return value R and a boolean into a function with 10 parameters returning an Option[R]
func Optionize2 ¶
Optionize2 converts a function with 2 parameters returning a tuple of a return value R and a boolean into a function with 2 parameters returning an Option[R]
func Optionize3 ¶
Optionize3 converts a function with 3 parameters returning a tuple of a return value R and a boolean into a function with 3 parameters returning an Option[R]
func Optionize4 ¶
func Optionize4[F ~func(T0, T1, T2, T3) (R, bool), T0, T1, T2, T3, R any](f F) func(T0, T1, T2, T3) Option[R]
Optionize4 converts a function with 4 parameters returning a tuple of a return value R and a boolean into a function with 4 parameters returning an Option[R]
func Optionize5 ¶
func Optionize5[F ~func(T0, T1, T2, T3, T4) (R, bool), T0, T1, T2, T3, T4, R any](f F) func(T0, T1, T2, T3, T4) Option[R]
Optionize5 converts a function with 5 parameters returning a tuple of a return value R and a boolean into a function with 5 parameters returning an Option[R]
func Optionize6 ¶
func Optionize6[F ~func(T0, T1, T2, T3, T4, T5) (R, bool), T0, T1, T2, T3, T4, T5, R any](f F) func(T0, T1, T2, T3, T4, T5) Option[R]
Optionize6 converts a function with 6 parameters returning a tuple of a return value R and a boolean into a function with 6 parameters returning an Option[R]
func Optionize7 ¶
func Optionize7[F ~func(T0, T1, T2, T3, T4, T5, T6) (R, bool), T0, T1, T2, T3, T4, T5, T6, R any](f F) func(T0, T1, T2, T3, T4, T5, T6) Option[R]
Optionize7 converts a function with 7 parameters returning a tuple of a return value R and a boolean into a function with 7 parameters returning an Option[R]
func Optionize8 ¶
func Optionize8[F ~func(T0, T1, T2, T3, T4, T5, T6, T7) (R, bool), T0, T1, T2, T3, T4, T5, T6, T7, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) Option[R]
Optionize8 converts a function with 8 parameters returning a tuple of a return value R and a boolean into a function with 8 parameters returning an Option[R]
func Optionize9 ¶
func Optionize9[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8) (R, bool), T0, T1, T2, T3, T4, T5, T6, T7, T8, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8) Option[R]
Optionize9 converts a function with 9 parameters returning a tuple of a return value R and a boolean into a function with 9 parameters returning an Option[R]
func Sequence ¶
func Sequence[A, HKTA, HKTOA any]( mof func(Option[A]) HKTOA, mmap func(func(A) Option[A]) func(HKTA) HKTOA, ) func(Option[HKTA]) HKTOA
Sequence converts an Option of some higher kinded type into the higher kinded type of an Option
func Traverse ¶ added in v1.0.24
func Traverse[A, B, HKTB, HKTOB any]( mof func(Option[B]) HKTOB, mmap func(func(B) Option[B]) func(HKTB) HKTOB, ) func(func(A) HKTB) func(Option[A]) HKTOB
Traverse converts an Option of some higher kinded type into the higher kinded type of an Option
func TraverseArray ¶
TraverseArray transforms an array
func TraverseArrayG ¶
TraverseArray transforms an array
func TraverseArrayWithIndex ¶ added in v1.0.29
TraverseArrayWithIndex transforms an array
func TraverseArrayWithIndexG ¶ added in v1.0.29
func TraverseArrayWithIndexG[GA ~[]A, GB ~[]B, A, B any](f func(int, A) Option[B]) func(GA) Option[GB]
TraverseArrayWithIndexG transforms an array
func TraverseRecord ¶
func TraverseRecord[K comparable, A, B any](f func(A) Option[B]) func(map[K]A) Option[map[K]B]
TraverseRecord transforms a record of options into an option of a record
func TraverseRecordG ¶
func TraverseRecordG[GA ~map[K]A, GB ~map[K]B, K comparable, A, B any](f func(A) Option[B]) func(GA) Option[GB]
TraverseRecordG transforms a record of options into an option of a record
func TraverseRecordWithIndex ¶ added in v1.0.29
func TraverseRecordWithIndex[K comparable, A, B any](f func(K, A) Option[B]) func(map[K]A) Option[map[K]B]
TraverseRecordWithIndex transforms a record of options into an option of a record
func TraverseRecordWithIndexG ¶ added in v1.0.29
func TraverseRecordWithIndexG[GA ~map[K]A, GB ~map[K]B, K comparable, A, B any](f func(K, A) Option[B]) func(GA) Option[GB]
TraverseRecordWithIndexG transforms a record of options into an option of a record
func TraverseTuple1 ¶
func TraverseTuple1[F1 ~func(A1) Option[T1], A1, T1 any](f1 F1) func(T.Tuple1[A1]) Option[T.Tuple1[T1]]
TraverseTuple1 converts a [Tuple1] of [A] via transformation functions transforming [A] to [Option[A]] into a [Option[Tuple1]].
func TraverseTuple10 ¶
func TraverseTuple10[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], F4 ~func(A4) Option[T4], F5 ~func(A5) Option[T5], F6 ~func(A6) Option[T6], F7 ~func(A7) Option[T7], F8 ~func(A8) Option[T8], F9 ~func(A9) Option[T9], F10 ~func(A10) Option[T10], A1, T1, A2, T2, A3, T3, A4, T4, A5, T5, A6, T6, A7, T7, A8, T8, A9, T9, A10, T10 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9, f10 F10) func(T.Tuple10[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10]) Option[T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]
TraverseTuple10 converts a [Tuple10] of [A] via transformation functions transforming [A] to [Option[A]] into a [Option[Tuple10]].
func TraverseTuple2 ¶
func TraverseTuple2[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], A1, T1, A2, T2 any](f1 F1, f2 F2) func(T.Tuple2[A1, A2]) Option[T.Tuple2[T1, T2]]
TraverseTuple2 converts a [Tuple2] of [A] via transformation functions transforming [A] to [Option[A]] into a [Option[Tuple2]].
func TraverseTuple3 ¶
func TraverseTuple3[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], A1, T1, A2, T2, A3, T3 any](f1 F1, f2 F2, f3 F3) func(T.Tuple3[A1, A2, A3]) Option[T.Tuple3[T1, T2, T3]]
TraverseTuple3 converts a [Tuple3] of [A] via transformation functions transforming [A] to [Option[A]] into a [Option[Tuple3]].
func TraverseTuple4 ¶
func TraverseTuple4[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], F4 ~func(A4) Option[T4], A1, T1, A2, T2, A3, T3, A4, T4 any](f1 F1, f2 F2, f3 F3, f4 F4) func(T.Tuple4[A1, A2, A3, A4]) Option[T.Tuple4[T1, T2, T3, T4]]
TraverseTuple4 converts a [Tuple4] of [A] via transformation functions transforming [A] to [Option[A]] into a [Option[Tuple4]].
func TraverseTuple5 ¶
func TraverseTuple5[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], F4 ~func(A4) Option[T4], F5 ~func(A5) Option[T5], A1, T1, A2, T2, A3, T3, A4, T4, A5, T5 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5) func(T.Tuple5[A1, A2, A3, A4, A5]) Option[T.Tuple5[T1, T2, T3, T4, T5]]
TraverseTuple5 converts a [Tuple5] of [A] via transformation functions transforming [A] to [Option[A]] into a [Option[Tuple5]].
func TraverseTuple6 ¶
func TraverseTuple6[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], F4 ~func(A4) Option[T4], F5 ~func(A5) Option[T5], F6 ~func(A6) Option[T6], A1, T1, A2, T2, A3, T3, A4, T4, A5, T5, A6, T6 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6) func(T.Tuple6[A1, A2, A3, A4, A5, A6]) Option[T.Tuple6[T1, T2, T3, T4, T5, T6]]
TraverseTuple6 converts a [Tuple6] of [A] via transformation functions transforming [A] to [Option[A]] into a [Option[Tuple6]].
func TraverseTuple7 ¶
func TraverseTuple7[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], F4 ~func(A4) Option[T4], F5 ~func(A5) Option[T5], F6 ~func(A6) Option[T6], F7 ~func(A7) Option[T7], A1, T1, A2, T2, A3, T3, A4, T4, A5, T5, A6, T6, A7, T7 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7) func(T.Tuple7[A1, A2, A3, A4, A5, A6, A7]) Option[T.Tuple7[T1, T2, T3, T4, T5, T6, T7]]
TraverseTuple7 converts a [Tuple7] of [A] via transformation functions transforming [A] to [Option[A]] into a [Option[Tuple7]].
func TraverseTuple8 ¶
func TraverseTuple8[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], F4 ~func(A4) Option[T4], F5 ~func(A5) Option[T5], F6 ~func(A6) Option[T6], F7 ~func(A7) Option[T7], F8 ~func(A8) Option[T8], A1, T1, A2, T2, A3, T3, A4, T4, A5, T5, A6, T6, A7, T7, A8, T8 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8) func(T.Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]) Option[T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]
TraverseTuple8 converts a [Tuple8] of [A] via transformation functions transforming [A] to [Option[A]] into a [Option[Tuple8]].
func TraverseTuple9 ¶
func TraverseTuple9[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], F4 ~func(A4) Option[T4], F5 ~func(A5) Option[T5], F6 ~func(A6) Option[T6], F7 ~func(A7) Option[T7], F8 ~func(A8) Option[T8], F9 ~func(A9) Option[T9], A1, T1, A2, T2, A3, T3, A4, T4, A5, T5, A6, T6, A7, T7, A8, T8, A9, T9 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9) func(T.Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]) Option[T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]
TraverseTuple9 converts a [Tuple9] of [A] via transformation functions transforming [A] to [Option[A]] into a [Option[Tuple9]].
func Unoptionize0 ¶
Unoptionize0 converts a function with 0 parameters returning a tuple of a return value R and a boolean into a function with 0 parameters returning an Option[R]
func Unoptionize1 ¶
Unoptionize1 converts a function with 1 parameters returning a tuple of a return value R and a boolean into a function with 1 parameters returning an Option[R]
func Unoptionize10 ¶
func Unoptionize10[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) Option[R], T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) (R, bool)
Unoptionize10 converts a function with 10 parameters returning a tuple of a return value R and a boolean into a function with 10 parameters returning an Option[R]
func Unoptionize2 ¶
Unoptionize2 converts a function with 2 parameters returning a tuple of a return value R and a boolean into a function with 2 parameters returning an Option[R]
func Unoptionize3 ¶
Unoptionize3 converts a function with 3 parameters returning a tuple of a return value R and a boolean into a function with 3 parameters returning an Option[R]
func Unoptionize4 ¶
func Unoptionize4[F ~func(T0, T1, T2, T3) Option[R], T0, T1, T2, T3, R any](f F) func(T0, T1, T2, T3) (R, bool)
Unoptionize4 converts a function with 4 parameters returning a tuple of a return value R and a boolean into a function with 4 parameters returning an Option[R]
func Unoptionize5 ¶
func Unoptionize5[F ~func(T0, T1, T2, T3, T4) Option[R], T0, T1, T2, T3, T4, R any](f F) func(T0, T1, T2, T3, T4) (R, bool)
Unoptionize5 converts a function with 5 parameters returning a tuple of a return value R and a boolean into a function with 5 parameters returning an Option[R]
func Unoptionize6 ¶
func Unoptionize6[F ~func(T0, T1, T2, T3, T4, T5) Option[R], T0, T1, T2, T3, T4, T5, R any](f F) func(T0, T1, T2, T3, T4, T5) (R, bool)
Unoptionize6 converts a function with 6 parameters returning a tuple of a return value R and a boolean into a function with 6 parameters returning an Option[R]
func Unoptionize7 ¶
func Unoptionize7[F ~func(T0, T1, T2, T3, T4, T5, T6) Option[R], T0, T1, T2, T3, T4, T5, T6, R any](f F) func(T0, T1, T2, T3, T4, T5, T6) (R, bool)
Unoptionize7 converts a function with 7 parameters returning a tuple of a return value R and a boolean into a function with 7 parameters returning an Option[R]
func Unoptionize8 ¶
func Unoptionize8[F ~func(T0, T1, T2, T3, T4, T5, T6, T7) Option[R], T0, T1, T2, T3, T4, T5, T6, T7, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) (R, bool)
Unoptionize8 converts a function with 8 parameters returning a tuple of a return value R and a boolean into a function with 8 parameters returning an Option[R]
func Unoptionize9 ¶
func Unoptionize9[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8) Option[R], T0, T1, T2, T3, T4, T5, T6, T7, T8, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8) (R, bool)
Unoptionize9 converts a function with 9 parameters returning a tuple of a return value R and a boolean into a function with 9 parameters returning an Option[R]
Types ¶
type Option ¶
type Option[A any] struct { // contains filtered or unexported fields }
Option defines a data structure that logically holds a value or not
Example (Creation) ¶
// Build an Option none1 := None[int]() some1 := Some("value") // Build from a value fromNillable := FromNillable[string] nonFromNil := fromNillable(nil) // None[*string] value := "value" someFromPointer := fromNillable(&value) // Some[*string](xxx) // some predicate isEven := func(num int) bool { return num%2 == 0 } fromEven := FromPredicate(isEven) noneFromPred := fromEven(3) // None[int] someFromPred := fromEven(4) // Some[int](4) fmt.Println(none1) fmt.Println(some1) fmt.Println(nonFromNil) fmt.Println(IsSome(someFromPointer)) fmt.Println(noneFromPred) fmt.Println(someFromPred)
Output: None[int] Some[string](value) None[*string] true None[int] Some[int](4)
Example (Extraction) ¶
noneValue := None[int]() someValue := Of(42) // Convert Option[T] to T fromNone, okFromNone := Unwrap(noneValue) // 0, false fromSome, okFromSome := Unwrap(someValue) // 42, true // Convert Option[T] with a default value noneWithDefault := GetOrElse(F.Constant(0))(noneValue) // 0 someWithDefault := GetOrElse(F.Constant(0))(someValue) // 42 // Apply a different function on None/Some(...) doubleOrZero := Fold( F.Constant(0), // none case N.Mul(2), // some case ) // func(ma Option[int]) int doubleFromNone := doubleOrZero(noneValue) // 0 doubleFromSome := doubleOrZero(someValue) // 84 // Pro-tip: Fold is short for the following: doubleOfZeroBis := F.Flow2( Map(N.Mul(2)), // some case GetOrElse(F.Constant(0)), // none case ) doubleFromNoneBis := doubleOfZeroBis(noneValue) // 0 doubleFromSomeBis := doubleOfZeroBis(someValue) // 84 fmt.Printf("%d, %t\n", fromNone, okFromNone) fmt.Printf("%d, %t\n", fromSome, okFromSome) fmt.Println(noneWithDefault) fmt.Println(someWithDefault) fmt.Println(doubleFromNone) fmt.Println(doubleFromSome) fmt.Println(doubleFromNoneBis) fmt.Println(doubleFromSomeBis)
Output: 0, false 42, true 0 42 0 84 0 84
func Do ¶ added in v1.0.107
Bind creates an empty context of type [S] to be used with the Bind operation
func FromNillable ¶
func MonadMapTo ¶
func MonadSequence2 ¶
func SequenceArray ¶
SequenceArray converts a homogeneous sequence of either into an either of sequence
func SequenceArrayG ¶
func SequencePair ¶ added in v1.0.128
SequencePair converts a [Pair] of [Option[T]] into an [Option[Pair]].
func SequenceRecord ¶
func SequenceRecord[K comparable, A any](ma map[K]Option[A]) Option[map[K]A]
SequenceRecord converts a homogeneous sequence of either into an either of sequence
func SequenceRecordG ¶
func SequenceRecordG[GA ~map[K]A, GOA ~map[K]Option[A], K comparable, A any](ma GOA) Option[GA]
func SequenceT1 ¶
SequenceT1 converts 1 parameters of [Option[T]] into a [Option[Tuple1]].
func SequenceT10 ¶
func SequenceT10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](t1 Option[T1], t2 Option[T2], t3 Option[T3], t4 Option[T4], t5 Option[T5], t6 Option[T6], t7 Option[T7], t8 Option[T8], t9 Option[T9], t10 Option[T10]) Option[T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]
SequenceT10 converts 10 parameters of [Option[T]] into a [Option[Tuple10]].
func SequenceT2 ¶
SequenceT2 converts 2 parameters of [Option[T]] into a [Option[Tuple2]].
func SequenceT3 ¶
func SequenceT3[T1, T2, T3 any](t1 Option[T1], t2 Option[T2], t3 Option[T3]) Option[T.Tuple3[T1, T2, T3]]
SequenceT3 converts 3 parameters of [Option[T]] into a [Option[Tuple3]].
func SequenceT4 ¶
func SequenceT4[T1, T2, T3, T4 any](t1 Option[T1], t2 Option[T2], t3 Option[T3], t4 Option[T4]) Option[T.Tuple4[T1, T2, T3, T4]]
SequenceT4 converts 4 parameters of [Option[T]] into a [Option[Tuple4]].
func SequenceT5 ¶
func SequenceT5[T1, T2, T3, T4, T5 any](t1 Option[T1], t2 Option[T2], t3 Option[T3], t4 Option[T4], t5 Option[T5]) Option[T.Tuple5[T1, T2, T3, T4, T5]]
SequenceT5 converts 5 parameters of [Option[T]] into a [Option[Tuple5]].
func SequenceT6 ¶
func SequenceT6[T1, T2, T3, T4, T5, T6 any](t1 Option[T1], t2 Option[T2], t3 Option[T3], t4 Option[T4], t5 Option[T5], t6 Option[T6]) Option[T.Tuple6[T1, T2, T3, T4, T5, T6]]
SequenceT6 converts 6 parameters of [Option[T]] into a [Option[Tuple6]].
func SequenceT7 ¶
func SequenceT7[T1, T2, T3, T4, T5, T6, T7 any](t1 Option[T1], t2 Option[T2], t3 Option[T3], t4 Option[T4], t5 Option[T5], t6 Option[T6], t7 Option[T7]) Option[T.Tuple7[T1, T2, T3, T4, T5, T6, T7]]
SequenceT7 converts 7 parameters of [Option[T]] into a [Option[Tuple7]].
func SequenceT8 ¶
func SequenceT8[T1, T2, T3, T4, T5, T6, T7, T8 any](t1 Option[T1], t2 Option[T2], t3 Option[T3], t4 Option[T4], t5 Option[T5], t6 Option[T6], t7 Option[T7], t8 Option[T8]) Option[T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]
SequenceT8 converts 8 parameters of [Option[T]] into a [Option[Tuple8]].
func SequenceT9 ¶
func SequenceT9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](t1 Option[T1], t2 Option[T2], t3 Option[T3], t4 Option[T4], t5 Option[T5], t6 Option[T6], t7 Option[T7], t8 Option[T8], t9 Option[T9]) Option[T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]
SequenceT9 converts 9 parameters of [Option[T]] into a [Option[Tuple9]].
func SequenceTuple1 ¶
SequenceTuple1 converts a [Tuple1] of [Option[T]] into an [Option[Tuple1]].
func SequenceTuple10 ¶
func SequenceTuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](t T.Tuple10[Option[T1], Option[T2], Option[T3], Option[T4], Option[T5], Option[T6], Option[T7], Option[T8], Option[T9], Option[T10]]) Option[T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]
SequenceTuple10 converts a [Tuple10] of [Option[T]] into an [Option[Tuple10]].
func SequenceTuple2 ¶
SequenceTuple2 converts a [Tuple2] of [Option[T]] into an [Option[Tuple2]].
func SequenceTuple3 ¶
func SequenceTuple3[T1, T2, T3 any](t T.Tuple3[Option[T1], Option[T2], Option[T3]]) Option[T.Tuple3[T1, T2, T3]]
SequenceTuple3 converts a [Tuple3] of [Option[T]] into an [Option[Tuple3]].
func SequenceTuple4 ¶
func SequenceTuple4[T1, T2, T3, T4 any](t T.Tuple4[Option[T1], Option[T2], Option[T3], Option[T4]]) Option[T.Tuple4[T1, T2, T3, T4]]
SequenceTuple4 converts a [Tuple4] of [Option[T]] into an [Option[Tuple4]].
func SequenceTuple5 ¶
func SequenceTuple5[T1, T2, T3, T4, T5 any](t T.Tuple5[Option[T1], Option[T2], Option[T3], Option[T4], Option[T5]]) Option[T.Tuple5[T1, T2, T3, T4, T5]]
SequenceTuple5 converts a [Tuple5] of [Option[T]] into an [Option[Tuple5]].
func SequenceTuple6 ¶
func SequenceTuple6[T1, T2, T3, T4, T5, T6 any](t T.Tuple6[Option[T1], Option[T2], Option[T3], Option[T4], Option[T5], Option[T6]]) Option[T.Tuple6[T1, T2, T3, T4, T5, T6]]
SequenceTuple6 converts a [Tuple6] of [Option[T]] into an [Option[Tuple6]].
func SequenceTuple7 ¶
func SequenceTuple7[T1, T2, T3, T4, T5, T6, T7 any](t T.Tuple7[Option[T1], Option[T2], Option[T3], Option[T4], Option[T5], Option[T6], Option[T7]]) Option[T.Tuple7[T1, T2, T3, T4, T5, T6, T7]]
SequenceTuple7 converts a [Tuple7] of [Option[T]] into an [Option[Tuple7]].
func SequenceTuple8 ¶
func SequenceTuple8[T1, T2, T3, T4, T5, T6, T7, T8 any](t T.Tuple8[Option[T1], Option[T2], Option[T3], Option[T4], Option[T5], Option[T6], Option[T7], Option[T8]]) Option[T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]
SequenceTuple8 converts a [Tuple8] of [Option[T]] into an [Option[Tuple8]].
func SequenceTuple9 ¶
func SequenceTuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](t T.Tuple9[Option[T1], Option[T2], Option[T3], Option[T4], Option[T5], Option[T6], Option[T7], Option[T8], Option[T9]]) Option[T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]
SequenceTuple9 converts a [Tuple9] of [Option[T]] into an [Option[Tuple9]].