Documentation ¶
Overview ¶
Package fngo contains many functions and types to help with a more functional style of programming.
Index ¶
- func Add[T Number](a, b T) T
- func Append[T any](coll []T, add T) []T
- func ButLast[T any](n int, coll []T) []T
- func Contains[T comparable](coll []T, want T) bool
- func Dec[T Number](a T) T
- func Dedupe[T comparable](coll []T) []T
- func Distinct[T comparable](coll []T) []T
- func Div[T Number](a, b T) T
- func Drop[T any](n int, coll []T) []T
- func EQ[T comparable](a, b T) bool
- func Empty[T any](coll []T) bool
- func Equal[T comparable](x, y []T) bool
- func Even(a int) bool
- func Filter[T any](f func(T) bool, coll []T) []T
- func First[T any](coll []T) T
- func Frequencies[T comparable](coll []T) map[T]int
- func GT[T Number](a, b T) bool
- func GroupBy[K comparable, V any](f func(V) K, coll []V) map[K][]V
- func Identity[T any](id T) T
- func Inc[T Number](a T) T
- func Iterate[T any](f func(T) T, ival T, limit int) []T
- func Juxt[I, O any](in I, fs ...func(I) O) []O
- func Keys[K comparable, V any](mp map[K]V) []K
- func LT[T Number](a, b T) bool
- func Last[T any](coll []T) T
- func Len[T any](a []T) int
- func Map[I, O any](f func(I) O, mp []I) []O
- func MapEqual[K, V comparable](x, y map[K]V) bool
- func MapMap[K, O comparable, V, A any](f func(K, V) (O, A), mp map[K]V) map[O]A
- func Mod(a, b int) int
- func Mul[T Number](a, b T) T
- func NEQ[T comparable](a, b T) bool
- func Odd(a int) bool
- func Partial[I, A, O any](f func(I, A) O, p I) func(A) O
- func PartialSecond[I, A, O any](f func(I, A) O, p A) func(I) O
- func Partition[T any](n int, coll []T) [][]T
- func PartitionBy[T any](f func(T, T) bool, coll []T) [][]T
- func PartitionStep[T any](n, step int, coll []T) [][]T
- func Range(start, end, step int) []int
- func RangeTo(end int) []int
- func ReduceLeft[I, O any](f func(O, I) O, init O, in []I) O
- func ReduceRight[I, O any](f func(O, I) O, init O, in []I) O
- func Reductions[I, O any](f func(O, I) O, init O, in []I) []O
- func Rest[T any](coll []T) []T
- func Reverse[T any](coll []T) []T
- func Rune(a int) rune
- func SplitAt[T any](n int, coll []T) [][]T
- func SplitBy(in string, delim rune) []string
- func StrLen(a string) int
- func String(a rune) string
- func Sub[T Number](a, b T) T
- func Take[T any](n int, coll []T) []T
- func Vals[K comparable, V any](mp map[K]V) []V
- func Zero[T Number](a T) bool
- type Number
- type Tuple
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Append ¶
func Append[T any](coll []T, add T) []T
Append is a helper functions to be able to use append as a function.
func Contains ¶
func Contains[T comparable](coll []T, want T) bool
Contains checks if a list contains an element.
func Dedupe ¶
func Dedupe[T comparable](coll []T) []T
Dedupe removes successive duplicates of a value.
func Distinct ¶
func Distinct[T comparable](coll []T) []T
Distinct returns a list with any duplicates removed.
func Equal ¶
func Equal[T comparable](x, y []T) bool
Equal checks if the elements of two lists are equal.
func Frequencies ¶
func Frequencies[T comparable](coll []T) map[T]int
Frequencies returns a map of all the different elements in a list and how many occurrences there are of each element.
func GroupBy ¶
func GroupBy[K comparable, V any](f func(V) K, coll []V) map[K][]V
GroupBy takes a monadic function f that returns a key for the returned map. f is applied to each element of coll, and element is put in a list at the return value of f in the map.
func Iterate ¶
Iterate takes a monadic function f and calls f(Last(returnList)) recursively until limit is met. [ival, f(ival), f(f(ival)), ...]
func Juxt ¶
func Juxt[I, O any](in I, fs ...func(I) O) []O
Juxt takes an input value and a list of functions, returning a list of the return values from the functions being called on the input value individually.
func Keys ¶
func Keys[K comparable, V any](mp map[K]V) []K
Keys returns all of the keys within a map.
func Map ¶
func Map[I, O any](f func(I) O, mp []I) []O
Map takes a function f, with the current element, returning an output element, and applies f to all elements in the input list, returning a list of the output type.
func MapEqual ¶
func MapEqual[K, V comparable](x, y map[K]V) bool
MapEqual checks if the elements of two maps are equal.
func MapMap ¶
func MapMap[K, O comparable, V, A any]( f func(K, V) (O, A), mp map[K]V, ) map[O]A
MapMap is like Map, but for maps! :D
func Partial ¶
func Partial[I, A, O any](f func(I, A) O, p I) func(A) O
Partial returns a function with 1 argument, where f has two arguments, and the first of the arguments is passed to Partial.
func PartialSecond ¶
func PartialSecond[I, A, O any](f func(I, A) O, p A) func(I) O
Partial returns a function with 1 argument, where f has two arguments, and the second of the arguments is passed to Partial.
func PartitionBy ¶
PartitionBy takes a function to compare the previous and current value and a collection to apply with. If the function returns true, a new sub-list is created in the partitioned list.
func PartitionStep ¶
PartitionStep returns a list of lists of the input list separated (or "partitioned") into the smaller equal-length sub-lists, scanned by the amount left after stepping.
func Range ¶
Range returns a list starting at start and doesn't go past end, stepping in intervals of step.
func ReduceLeft ¶
func ReduceLeft[I, O any](f func(O, I) O, init O, in []I) O
ReduceLeft takes a function f, with an accumulator and the current element of the list. The accumulator is initialized to the init argument, and is returned after the function. Goes left to right.
func ReduceRight ¶
func ReduceRight[I, O any](f func(O, I) O, init O, in []I) O
ReduceRight takes a function f, with an accumulator and the current element of the list. The accumulator is initialized to the init argument, and is returned after the function. Goes right to left.
func Reductions ¶
func Reductions[I, O any](f func(O, I) O, init O, in []I) []O
Reductions takes a funciton f, with an accumulator and the current element of the list. The accumulator is initialized to the init argument, and each iteration of the accumulator is returned after the function as a list. Another common name for Reductions is Scan.
func Reverse ¶
func Reverse[T any](coll []T) []T
Reverse returns the reversed version of the list given to it.
func SplitAt ¶
SplitAt takes a collection and splits it into two sub-lists, split at the index of n.
func Vals ¶
func Vals[K comparable, V any](mp map[K]V) []V
Vals returns all of the values within a map.
Types ¶
type Number ¶
type Number interface { constraints.Integer | constraints.Float }
Number is a type interface meant to be either integer or float.