Documentation ¶
Index ¶
- func DeriveMonoid[T any](s algebra.Semigroup[T]) algebra.Monoid[Option[T]]
- func DeriveSemigroup[T any](s algebra.Semigroup[T]) algebra.Semigroup[Option[T]]
- func Equal[T comparable](x, y Option[T]) bool
- func Find[T any](xs Option[T], fn func(T) bool) (T, bool)
- func FindElem[T any](eq cmp.Eq[T]) func(xs Option[T], e T) (T, bool)
- func Fold[T any, U any](init T, xs Option[U], fn func(T, U) T) T
- func ForEach[T any](xs Option[T], fn func(T))
- func IsSome[T any](x Option[T]) bool
- func Max[T any](ord cmp.Ord[T]) func(xs Option[T]) (T, bool)
- func MaxBy[T any](xs Option[T], less func(T, T) bool) (T, bool)
- func Min[T any](ord cmp.Ord[T]) func(xs Option[T]) (T, bool)
- func MinBy[T any](xs Option[T], less func(T, T) bool) (T, bool)
- func Sum[T any](m algebra.Monoid[T]) func(xs Option[T]) T
- func SumWithInit[T any](s algebra.Semigroup[T]) func(init T, xs Option[T]) T
- func Unwrap[T any](x Option[T]) T
- func UnwrapOr[T any](x Option[T], def T) T
- func UnwrapOrElse[T any](x Option[T], def func() T) T
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeriveMonoid ¶
DeriveMonoid derives Monoid[Option[T]] from Semigroup[T]. T doesn't need to be Monoid since the None() is the identity element of the monoid.
func DeriveSemigroup ¶
DeriveSemigroup derives Semigroup[Option[T]] from Semigroup[T]
func Equal ¶
func Equal[T comparable](x, y Option[T]) bool
Equal returns true if and only if the two value x and y are the same, that is, both x and y are nil or both have the same value in the sense of ==.
func Find ¶
Find returns a first element in xs that satisfies the given predicate fn. It returns false as a second return value if no elements are found.
func FindElem ¶
FindElem returns a first element in xs that equals to e in the sense of given Eq. It returns false as a second return value if no elements are found.
func Max ¶
Max returns the largest element with respect to the given Ord. It returns <zero value>, false if the collection is empty.
func MaxBy ¶
MaxBy returns the smallest element with respect to the given function. It returns <zero value>, false if the collection is empty.
func Min ¶
Min returns the smallest element with respect to the given Ord. It returns <zero value>, false if the collection is empty.
func MinBy ¶
MinBy returns the smallest element with respect to the given function. It returns <zero value>, false if the collection is empty.
func SumWithInit ¶
SumWithInit sums up init and all values in xs.
func UnwrapOrElse ¶
UnwrapOrElse returns a value that x has. It returns def() if x has no value.
Types ¶
type Option ¶
type Option[T any] struct { // contains filtered or unexported fields }
Option is an optional value.
func Filter ¶
Filter returns a collection that only returns elements that satisfies given predicate.
func FromIterator ¶
FromIterator returns an Option that has the first element in the given Iterator. It returns None() if the iterator has no value.