Documentation
¶
Index ¶
- func All[T any](s []T, p func(v T) bool) bool
- func Any[T any](s []T, p func(v T) bool) bool
- func Cons[T any](v []T, n int) [][]T
- func Count[T any](s []T, f func(v T) bool) int
- func CountBy[T any, U comparable](s []T, f func(v T) U) map[U]int
- func EachCons[T any](v []T, n int, f func(v []T))
- func EachSlice[T any](v []T, n int, f func(v []T))
- func EachSliceBetween[T any](v []T, slicer func(a, b T) bool, f func(v []T))
- func EachSliceBy[T any, U comparable](v []T, slicer func(a T) U, f func(v []T))
- func EachZip[T any](v [][]T, f func(v []T))
- func Filter[T any](v []T, f func(a T) bool) []T
- func FilterMap[T any, U any](v []T, f func(a T) (U, bool)) []U
- func FilterMapCons[T any, U any](v []T, n int, f func(a []T) (U, bool)) []U
- func FilterMapSlice[T any, U any](v []T, n int, f func(a []T) (U, bool)) []U
- func FilterMapSliceBetween[T any, U any](v []T, slicer func(a, b T) bool, f func(a []T) (U, bool)) []U
- func FilterMapSliceBy[T any, U comparable, V any](v []T, slicer func(a T) U, f func(a []T) (V, bool)) []V
- func FilterMapZip[T any, U comparable](v [][]T, f func(a []T) (U, bool)) []U
- func FlatMap[T any, U any](v []T, f func(a T) []U) []U
- func FlatMapCons[T any, U any](v []T, n int, f func(a []T) []U) []U
- func FlatMapSlice[T any, U any](v []T, n int, f func(a []T) []U) []U
- func FlatMapSliceBetween[T any, U any](v []T, slicer func(a, b T) bool, f func(a []T) []U) []U
- func FlatMapSliceBy[T any, U comparable, V any](v []T, slicer func(a T) U, f func(a []T) []V) []V
- func FlatMapZip[T any, U comparable](v [][]T, f func(a []T) []U) []U
- func GroupBy[T any, U comparable](v []T, f func(v T) U) map[U][]T
- func Make[T any](v ...T) []T
- func Map[T any, U any](v []T, f func(a T) U) []U
- func MapCons[T any, U any](v []T, n int, f func(a []T) U) []U
- func MapSlice[T any, U any](v []T, n int, f func(a []T) U) []U
- func MapSliceBetween[T any, U any](v []T, slicer func(a, b T) bool, f func(a []T) U) []U
- func MapSliceBy[T any, U comparable, V any](v []T, slicer func(a T) U, f func(a []T) V) []V
- func MapZip[T any, U comparable](v [][]T, f func(a []T) U) []U
- func Max[T constraints.Ordered](v []T) T
- func MaxBy[T any, U constraints.Ordered](v []T, f func(a T) U) T
- func Min[T constraints.Ordered](v []T) T
- func MinBy[T any, U constraints.Ordered](v []T, f func(a T) U) T
- func MinMax[T constraints.Ordered](v []T) (T, T)
- func MinMaxBy[T any, U constraints.Ordered](v []T, f func(a T) U) (T, T)
- func None[T any](s []T, p func(v T) bool) bool
- func One[T any](s []T, p func(v T) bool) bool
- func Reduce[T, U any](v []T, memo U, f func(a T, memo U) U) U
- func Slice[T any](v []T, n int) [][]T
- func SliceBetween[T any](v []T, slicer func(a, b T) bool) [][]T
- func SliceBy[T any, U comparable](v []T, slicer func(a T) U) [][]T
- func Sort[T any](v []T, less func(a, b T) bool) []T
- func SortBy[T any, U constraints.Ordered](v []T, f func(a T) U) []T
- func StableSort[T any](v []T, less func(a, b T) bool) []T
- func StableSortBy[T any, U constraints.Ordered](v []T, f func(a T) U) []T
- func Uniq[T comparable](v []T) []T
- func UniqBy[T any, U comparable](v []T, f func(a T) U) []T
- func Zip[T any](v ...[]T) [][]T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cons ¶
Cons returns a slice of slices consisting of successive overlapping n-tuple of elements. All resulting slices have a length of `n`. The result is empty if the input is shorter than `n`.
func Count ¶ added in v0.0.2
Count invokes `f` with each element of `v` and counts the true results.
func CountBy ¶ added in v0.0.2
func CountBy[T any, U comparable](s []T, f func(v T) U) map[U]int
CountBy invokes `f` with each element of `v` and counts the number of elements for each value returned by `f`.
func EachSliceBetween ¶
EachSliceBetween invokes `f` with each element returned by SliceBetween()
func EachSliceBy ¶
func EachSliceBy[T any, U comparable](v []T, slicer func(a T) U, f func(v []T))
EachSliceBy invokes `f` with each element returned by SliceBy()
func EachZip ¶
func EachZip[T any](v [][]T, f func(v []T))
EachZip invokes `f` with each element returned by Zip(). The arguments must be passed as slice rather than variadic because of the trailing function argument.
func Filter ¶ added in v0.0.2
Filter returns a copy of v that includes only the elements for which `f` returns true.
func FilterMap ¶ added in v0.0.2
FlatMap invokes `f` with each element of `v` and collects zero or one result per element.
func FilterMapCons ¶ added in v0.0.2
FilterMapCons invokes `f` with each `Cons(n)` of `v` and collects zero or one result per invocation.
func FilterMapSlice ¶ added in v0.0.2
FilterMapSlice invokes `f` with each `Slice(n)` of `v` and collects zero or one result per invocation.
func FilterMapSliceBetween ¶ added in v0.0.2
func FilterMapSliceBetween[T any, U any](v []T, slicer func(a, b T) bool, f func(a []T) (U, bool)) []U
FilterMapSliceBetween slices `v` according to `slicer`, invokes `f` with each slice and collects zero or one result per invocation.
func FilterMapSliceBy ¶ added in v0.0.2
func FilterMapSliceBy[T any, U comparable, V any](v []T, slicer func(a T) U, f func(a []T) (V, bool)) []V
FilterMapSliceBy slices `v` according to `slicer`, invokes `f` with each slice and collects zero or one result per invocation.
func FilterMapZip ¶ added in v0.0.2
func FilterMapZip[T any, U comparable](v [][]T, f func(a []T) (U, bool)) []U
FilterMapZip zips the slices of v into one tuple per matching index, invokes `f` with each tuple and collects zero or one result per invocation.
func FlatMap ¶ added in v0.0.2
FlatMap invokes `f` with each element of `v` and collects zero, one or more results per element.
func FlatMapCons ¶ added in v0.0.2
FlatMapCons invokes `f` with each `Cons(n)` of `v` and collects zero, one or more results per invocation.
func FlatMapSlice ¶ added in v0.0.2
FlatMapSlice invokes `f` with each `Slice(n)` of `v` and collects zero, one or more results per invocation.
func FlatMapSliceBetween ¶ added in v0.0.2
FlatMapSliceBetween slices `v` according to `slicer`, invokes `f` with each slice and collects zero, one or more results per invocation.
func FlatMapSliceBy ¶ added in v0.0.2
func FlatMapSliceBy[T any, U comparable, V any](v []T, slicer func(a T) U, f func(a []T) []V) []V
FlatMapSliceBy slices `v` according to `slicer`, invokes `f` with each slice and collects zero, one or more results per invocation.
func FlatMapZip ¶ added in v0.0.2
func FlatMapZip[T any, U comparable](v [][]T, f func(a []T) []U) []U
FlatMapZip zips the slices of v into one tuple per matching index, invokes `f` with each tuple and collects zero, one or more results per invocation.
func GroupBy ¶ added in v0.0.2
func GroupBy[T any, U comparable](v []T, f func(v T) U) map[U][]T
GroupBy returns a map that groups all the elements of `v` by the value returned by `f`.
func Make ¶
func Make[T any](v ...T) []T
Make is an helper function that creates a slice from individual elements using type inference to determine the type of the resulting slice. All input elements must have matching type.
func Map ¶ added in v0.0.2
Map invokes `f` with each element of `v` and collects one result per element.
func MapCons ¶ added in v0.0.2
MapCons invokes `f` with each `Cons(n)` of `v` and collects one result per invocation.
func MapSlice ¶ added in v0.0.2
MapSlice invokes `f` with each `Slice(n)` of `v` and collects one result per invocation.
func MapSliceBetween ¶ added in v0.0.2
MapSliceBetween slices `v` according to `slicer`, invokes `f` with each slice and collects one result per invocation.
func MapSliceBy ¶ added in v0.0.2
func MapSliceBy[T any, U comparable, V any](v []T, slicer func(a T) U, f func(a []T) V) []V
MapSliceBy slices `v` according to `slicer`, invokes `f` with each slice and collects one result per invocation.
func MapZip ¶ added in v0.0.2
func MapZip[T any, U comparable](v [][]T, f func(a []T) U) []U
MapZip zips the slices of v into one tuple per matching index, invokes `f` with each tuple and collects one result per invocation.
func Max ¶
func Max[T constraints.Ordered](v []T) T
Max returns the maximum value of `v`. The type of `v` must be a slice with a value type that defines a strict ordered relationship. If `v` is empty, the function return the zero value of the underlying value type.
func MaxBy ¶
func MaxBy[T any, U constraints.Ordered](v []T, f func(a T) U) T
MaxBy returns the first element of `v` for which the result of invoking `f` yields the largest value. If `v` is empty, the zero value of the underlying value type is returned.
func Min ¶
func Min[T constraints.Ordered](v []T) T
Min returns the minimum value of `v`. The type of `v` must be a slice with a value type that defines a strict ordered relationship. If `v` is empty, the function return the zero value of the underlying value type.
func MinBy ¶
func MinBy[T any, U constraints.Ordered](v []T, f func(a T) U) T
MinBy returns the first element of `v` for which the result of invoking `f` yields the smallest value. If `v` is empty, the zero value of the underlying value type is returned.
func MinMax ¶
func MinMax[T constraints.Ordered](v []T) (T, T)
MinMax returns both the minimum abd maximum value of `v`. The type of `v` must be a slice with a value type that defines a strict ordered relationship. If `v` is empty, the function return a pair of zero values for the underlying value type.
func MinMaxBy ¶
func MinMaxBy[T any, U constraints.Ordered](v []T, f func(a T) U) (T, T)
MinMaxBy returns the first elements of `v` for which the result of invoking `f` yields the smallest and the largest values. If `v` is empty, zero values of the underlying value type are returned.
func Reduce ¶ added in v0.0.2
func Reduce[T, U any](v []T, memo U, f func(a T, memo U) U) U
Reduce invokes `f` with each element of `v` and the updated memo from the previous invocation.
func Slice ¶
Slice returns a slice of slices consisting of successive non-overlapping n-tuple of elements. All resulting slices have a length of `n`, except the last one which may be shorter.
func SliceBetween ¶
SliceBetween invokes the slicer function with each consecutive element (`a`, `b`) and splits the input between `a` and `b` if the slicer returns true. The result is a slice of slices containing all the resulting splits.
func SliceBy ¶
func SliceBy[T any, U comparable](v []T, slicer func(a T) U) [][]T
SliceBy splits the input into contiguous slices for which the function 'slicer' returns the same value.
func Sort ¶
Sort returns a sorted copy of `v` according to the comparison function `less`. The original slice is not modified.
func SortBy ¶
func SortBy[T any, U constraints.Ordered](v []T, f func(a T) U) []T
SortBy returns a sorted copy of `v` to the natural sort order of the result of invoking `f` on each element. The original slice is not modified.
func StableSort ¶
StableSort returns a sorted copy of `v` according to the comparison function `less`, preserving the original order of elements that compare equal. The original slice is not modified.
func StableSortBy ¶
func StableSortBy[T any, U constraints.Ordered](v []T, f func(a T) U) []T
StableSortBy returns a sorted copy of `v` according to the natural sort order of the result of invoking `f` on each element, preserving the original order of elements that compare equal. The original slice is not modified.
func Uniq ¶
func Uniq[T comparable](v []T) []T
Uniq returns a copy of `v` where only the first occurrance of a value is preserved. The input must be a slice of comparable values, but does not have to be sorted.
func UniqBy ¶
func UniqBy[T any, U comparable](v []T, f func(a T) U) []T
UniqBy returns a copy of `v` where only the first occurrance of a value is preserved. Values are considered equal if the results of invoking `f` on them are equal. The input does not have to be sorted.
Types ¶
This section is empty.