Documentation ¶
Index ¶
- func Accumulate[InType, OutType any](f func(OutType, InType) OutType, init OutType, s []InType) OutType
- func Combine[T1, T2, T3 any](s1 []T1, s2 []T2, zipper func(T1, T2) T3) []T3
- func Exists[T any](f func(T) bool, s []T) bool
- func Filter[T any](f func(T) bool, s []T) []T
- func ForAll[T any](f func(T) bool, s []T) bool
- func Insert[T any](x T, pos int, s []T) []T
- func Iter[T any](s []T, f func(T))
- func LowerBound[T constraints.Ordered](x T, s []T) int
- func Map[InType, OutType any](in []InType, f func(InType) OutType) []OutType
- func OptionalFilter[T1, T2 any](f func(T1) Option[T2], s []T1) []T2
- func Partition[T constraints.Ordered](x T, s []T) int
- func PartitionFilter[T any](f func(T) bool, s []T) int
- func Reverse[T any](s []T)
- type Option
- type OptionImplem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Accumulate ¶
func Accumulate[InType, OutType any](f func(OutType, InType) OutType, init OutType, s []InType) OutType
Accumulate traverses s and accumulates results of function f with initial value init Accumulate(f, init, {a1, ..., bn}) -> f( ... f(f(init, a1), a2) ..., an)
func Combine ¶
func Combine[T1, T2, T3 any](s1 []T1, s2 []T2, zipper func(T1, T2) T3) []T3
Combine combines elements of s1 and s2 using zipper function returned slice of the length of the smallest input
func Insert ¶
Insert inserts x as position pos in s if pos >= len(s) insert at the end of s panic if pos is less than 0
func LowerBound ¶
func LowerBound[T constraints.Ordered](x T, s []T) int
LowerBound returns the position of the first elements that is not smaller than x LowerBound returns a coherent result only if s is sorted
func Map ¶
func Map[InType, OutType any](in []InType, f func(InType) OutType) []OutType
Map converts a slice of InType into a slice of OutType using function f
func OptionalFilter ¶
OptionalFilter returns the slice made of f(e) for all e in s such that f(e).HasValue() is true
func Partition ¶
func Partition[T constraints.Ordered](x T, s []T) int
Partition moves elements to form a partition and returns the position of the pivot Let p := Partition(x, s) then for all i < p s[i] < x and for all i >= p, s[i] >= x
func PartitionFilter ¶
PartitionFilter moves elements to form a partition w.r.t to f Let p := PartitionFilter(f, s) then for all i < p, f([i]) is true and for all i >= p f(s[i]) is false
Types ¶
type Option ¶
type Option[T any] interface { HasValue() bool Value() T Do(func(T)) Option[T] Else(func()) Option[T] }
func OptionalDo ¶
OptionalDo calls f(o.Value()) if o is not empty and returns o in all cases
func OptionalElse ¶
OptionalElse calls f if o is empty and returns o in all cases
func OptionalFlatMap ¶
OptionalFlatMap returns the result of f(o.Value()) if o has a value, returns an empty optional otherwise Similar to OptionalMap but for function that already returns an optional type
func OptionalMap ¶
OptionalMap returns an option value result from f(o.Value()) if o is not empty, returns an empty optional otherwise
type OptionImplem ¶
type OptionImplem[T any] struct { // contains filtered or unexported fields }
OptionImplem model an optional value
func NewOption ¶
func NewOption[T any](v T) *OptionImplem[T]
NewOption returns an optional value containing v
func (*OptionImplem[T]) Do ¶
func (o *OptionImplem[T]) Do(f func(T)) Option[T]
Do calls f(o.Value()) if o is not empty and returns o in all cases
func (*OptionImplem[T]) Else ¶
func (o *OptionImplem[T]) Else(f func()) Option[T]
Else calls f if o is empty and returns o in all cases
func (*OptionImplem[T]) HasValue ¶
func (o *OptionImplem[T]) HasValue() bool
HasValue returns true if the optional has a value
func (*OptionImplem[T]) Value ¶
func (o *OptionImplem[T]) Value() T
Value returns the content of the optional value, panic if empty