Documentation ¶
Index ¶
- func Apply[S ~[]E, E any, R any](slice S, fn func(E) R) []R
- func ApplyInPlace[S ~[]E, E any](slice *S, fn func(E) E)
- func ApplyInPlaceWithIndex[S ~[]E, E any](slice *S, fn func(int, E) E)
- func ApplyWithIndex[S ~[]E, E any, R any](slice S, fn func(int, E) R) []R
- func Filter[S ~[]E, E any](slice S, fn func(E) bool) S
- func FilterWithIndex[S ~[]E, E any](slice S, fn func(int, E) bool) S
- func Range[N Number](from N, to N) []N
- func RangeWithStep[N Number](from N, to N, step N) []N
- func Reduce[S ~[]E, E any](slice S, fn func(E, E) E) E
- func ReduceRight[S ~[]E, E any](slice S, fn func(E, E) E) E
- func Reverse[S ~[]E, E any](s S) S
- func Scan[S ~[]E, E any](slice S, fn func(E, E) E) S
- func ScanWithIndex[S ~[]E, E any](slice S, fn func(e1 E, i1 int, e2 E, i2 int) E) S
- type Number
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply applies function fn to each element of the slice and returns it.
The returning slice can be of a differnt type.
func ApplyInPlace ¶ added in v1.1.0
func ApplyInPlace[S ~[]E, E any](slice *S, fn func(E) E)
Like Apply but works on the slice directly/in-place.
func ApplyInPlaceWithIndex ¶ added in v1.1.0
Like ApplyInPlace, but function fn takes the index of the element as a parameter.
func ApplyWithIndex ¶
Like Apply, but function fn takes the index of the element as a parameter.
func FilterWithIndex ¶
Like Filter, but function fn takes the index of the element as a parameter.
func RangeWithStep ¶
func RangeWithStep[N Number](from N, to N, step N) []N
Creates a slice of numbers with a specific step in an inclusive range [from, to]. Supports descending ranges.
Panics if step is negative (should still be positive for descending ranges).
func Reduce ¶
func Reduce[S ~[]E, E any](slice S, fn func(E, E) E) E
Return value after applying dyadic function fn to each neighboring element from left to right, where a is the element on the left and b on the right.
func ReduceRight ¶ added in v1.1.0
func ReduceRight[S ~[]E, E any](slice S, fn func(E, E) E) E
Like Reduce but from right to left. a is the element on the right while b is the one on the left.
func Reverse ¶
func Reverse[S ~[]E, E any](s S) S
Reverse wraps slices.Reverse, but returns the slice instead.
func Scan ¶
func Scan[S ~[]E, E any](slice S, fn func(E, E) E) S
Reduce, but keep intermediate values. Based on APL's scan.