Documentation ¶
Index ¶
- func All[T any](p func(T) bool, s []T) bool
- func Any[T any](p func(T) bool, s []T) bool
- func Comp[T any](fs ...func(T) T) func(T) T
- func Comp2[TIn any, TMid any, TOut any](f func(TMid) TOut, g func(TIn) TMid) func(TIn) TOut
- func CompR[T any](fs ...func(T) T) func(T) T
- func Curry()
- func Filter[T any](p func(T) bool, s []T) []T
- func FindAll[T any](p func(T) bool, s []T) []int
- func FindIndex[T any](p func(T) bool, s []T) int
- func FindIndices[T any](p func(T) bool, s []T) []int
- func Map[TIn any, TOut any](f func(TIn) TOut, s []TIn) []TOut
- func PartApply()
- func Reduce[TIn any, TAcc any](f func(TAcc, TIn) TAcc, s []TIn) TAcc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All ¶
Any takes a predicate `p` and a slice `s` and returns true if all element of `s` satisfy `p` (and false otherwise).
func Any ¶
Any takes a predicate `p` and a slice `s` and returns true if any element of `s` satisfies `p` (and false otherwise).
func Comp ¶
func Comp[T any](fs ...func(T) T) func(T) T
Comp is a high-order function that implements composition. Given an arbitrary number of functions as input, Comp will return a function so that Comp(f, g)(x) == f(g(x)).
This is an initial implementation which works only on functions that return the same type as their input.
func Comp2 ¶
Comp2 is a high-order function that implements composition. Given two functions as input, it will return a function so that Comp2(f, g)(x) == f(g(x)).
When composing two functions, this one is more preferable to CompAll as it has less general type constraints.
func CompR ¶
func CompR[T any](fs ...func(T) T) func(T) T
CompR is the inverse of Comp. Given an arbitrary number of functions as input, Comp will return a function so that Comp(f, g)(x) == g(f(x)).
This is an initial implementation which works only on functions that return the same type as their input.
func Filter ¶
Filter implements the common high-order function `filter`. It takes a function (predicate) and a slice of some type, and it returns a slice containing the elements of the input slice for which the predicate returns true.
func FindIndex ¶
FindIndex takes a predicate `p` and a slice `s` and returns the index of the first element that satisfies `p`. It returns -1 if no element is found.
See FindIndices if you want to return all indices.
func FindIndices ¶
FindIndices takes a predicate `p` and a slice `s` and returns an int slice of all the indices of the elements that satisfy `p`.
See FindIndex if you want to return the first index only.
func Map ¶
Map implements the common high-order function `map`. It takes a function and a slice of some type, applies the function on each element of the slice, and returns a new slice of the same type.
func Reduce ¶
Reduce implements the common high-order function `reduce`. It takes a function and a slice. The input function must have two parameters so that the first one would be the "accumulator" and the second would be the next element in the slice.
Note that the initial value of the accumulator is set to the zero value of whatever type (T) returned by Reduce.
Types ¶
This section is empty.