Documentation ¶
Index ¶
- func Even[T constraints.Integer](n T) bool
- func Fill[T any](s []T, v T) []T
- func Filter[T any](s []T, fn func(T) bool) []T
- func ForEach[T any](s []T, f func(int, T))
- func Map[T any](s []T, fn func(T) T) []T
- func Nth[T any](index int, elems []T) T
- func Odd[T constraints.Integer](n T) bool
- func Range[T constraints.Integer](start, end T) []T
- func Reduce[T, M any](s []T, f func(M, T) M, initValue M) M
- func Sum[T constraints.Float | constraints.Integer](nums []T) T
- func Uniq[T comparable](s []T) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Filter ¶
The Filter function is a higher-order function in programming that takes an input slice and applies the s to each element of the slice, deciding whether to keep or discard the element based on the truth value of the function's return. It returns a new slice of the filtered results. It allows for easy filtering of data without the need for explicit iteration or looping over the original slice.
func ForEach ¶
ForEach applies the function f to each element of the s. The function f takes an integer as its argument and returns nothing.
func Map ¶
func Map[T any](s []T, fn func(T) T) []T
The Map function is a higher-order function in programming that takes an input slice and applies the s to each element of the slice, returning a new slice of the results. It allows for easy transformation of data without the need for explicit iteration or looping over the original slice.
func Range ¶
func Range[T constraints.Integer](start, end T) []T
Range applies give a slice from start to end.
func Reduce ¶
func Reduce[T, M any](s []T, f func(M, T) M, initValue M) M
The Reduce function is a higher-order function in programming that takes an input slice and applies the s to the elements of the slice in a cumulative way, reducing the slice to a single value. It iteratively applies the function to the elements of the slice, accumulating the result at each step, until a single value is obtained. It allows for easy aggregation of data without the need for explicit iteration or looping over the original slice.
func Sum ¶
func Sum[T constraints.Float | constraints.Integer](nums []T) T
Give the sum of the slice.
Types ¶
This section is empty.