Documentation ¶
Overview ¶
Package fn contains the sort of non-Go-like, occasionally higher-order, utility functions you might find in a functional language.
Index ¶
- func All[S ~[]E, F ~func(E) bool, E any](s S, f F) bool
- func Any[S ~[]E, F ~func(E) bool, E any](s S, f F) bool
- func CountIf[S ~[]E, F ~func(E) bool, E any](s S, f F) (count int)
- func Filter[S ~[]E, P ~func(E) bool, E any](s S, p P) (out []E)
- func ForEach[S ~[]E, F ~func(E), E any](s S, f F)
- func Head[S ~[]E, E any](s S, def E) E
- func If[T any](c bool, t, f T) T
- func Keys[M ~map[K]V, K comparable, V any](m M) []K
- func Map[S ~[]I, F ~func(I) O, I, O any](in S, f F) (out []O)
- func MapE[S ~[]I, F ~func(I) (O, error), I, O any](in S, f F) (out []O, err error)
- func MapRange[F ~func(I) E, I integer, E any](start, end I, f F) (out []E)
- func Max[S ~[]E, E cmp.Ordered](s S) (result E)
- func MaxF[S ~[]I, F ~func(I) O, I any, O cmp.Ordered](s S, f F) (result O)
- func Min[S ~[]E, E cmp.Ordered](s S) (result E)
- func MinF[S ~[]I, F ~func(I) O, I any, O cmp.Ordered](s S, f F) (result O)
- func Prod[S ~[]E, E integer](s S) (result E)
- func ProdF[S ~[]I, F ~func(I) O, I any, O integer](s S, f F) (result O)
- func Sum[S ~[]E, E integer](s S) (result E)
- func SumF[S ~[]I, F ~func(I) O, I any, O integer](s S, f F) (result O)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All ¶
All returns true if the function f returns true for all elements of slice s. Returns true for an empty slice.
func Any ¶
Any returns true if the function f returns true for at least one element of slice s. Returns false for an empty slice.
func ForEach ¶
func ForEach[S ~[]E, F ~func(E), E any](s S, f F)
ForEach invokes a function (which must not return anything) for each element of a slice in order.
func Head ¶
func Head[S ~[]E, E any](s S, def E) E
Head returns the first line of a slice, or a default value for an empty slice.
func If ¶
If is an expression conditional, similar to the C `?:` operator (except both branches are evaluated).
func Keys ¶
func Keys[M ~map[K]V, K comparable, V any](m M) []K
Keys returns a slice consisting of the keys of a map. The keys are in no particular order, the same as the iteration order of a map.
func Map ¶
func Map[S ~[]I, F ~func(I) O, I, O any](in S, f F) (out []O)
Map returns a new slice that contains the results of applying the given function to each element of the input slice.
func MapRange ¶
func MapRange[F ~func(I) E, I integer, E any](start, end I, f F) (out []E)
MapRange returns a slice with the results of calling function on a range of integers. The range is given in the usual half-open [start, end) style.
func Prod ¶
func Prod[S ~[]E, E integer](s S) (result E)
Prod returns the product of a slice of integers. The product of an empty slice is 1.
func ProdF ¶
func ProdF[S ~[]I, F ~func(I) O, I any, O integer](s S, f F) (result O)
ProdF returns the product of the results of applying a function to a slice. The product of an empty slice is 1.
Types ¶
This section is empty.