Documentation
¶
Index ¶
- Constants
- func Accumulate[R any, T any, AF AccumulatorFunc[T, R], S ~[]T](ss S, accumulator AF) R
- func AccumulateIf[R any, T any, SF SelectFunc[T], AF AccumulatorFunc[T, R], S ~[]T](ss S, selector SF, accumulator AF) R
- func All[T any, SF SelectFunc[T], S ~[]T](ss S, selector SF) bool
- func Any[T any, SF SelectFunc[T], S ~[]T](ss S, selector SF) bool
- func Contains[T comparable, S ~[]T](ss S, s T) bool
- func Diff[T cmp.Ordered, S []T](a, b S) (S, S)
- func DiffFunc[T any, EF EqualFunc[T], S ~[]T](a, b S, equalFunc EF) S
- func Flatten[T any, S ~[]T, SS ~[]S](ss SS) S
- func GroupBy[S ~[]T, K comparable, KF KeyFunc[T, K], T any](ss S, keyFunc KF) map[K]S
- func Index[T comparable, S ~[]T](ss S, s T) int
- func IndexFunc[T any, SF SelectFunc[T], S ~[]T](ss S, selector SF) int
- func Intersect[T cmp.Ordered, S []T](a, b S) S
- func IntersectFunc[T any, EF EqualFunc[T], S ~[]T](a, b S, equalFunc EF) S
- func LenIf[T any, SF SelectFunc[T], S ~[]T](ss S, selector SF) int
- func Map[R any, T any, MF MapFunc[T, R], S ~[]T](ss S, mapping MF) []R
- func MapConcurrent[R any, T any, MF MapFunc[T, R], S ~[]T](ss S, mapping MF, concurrency uint16) []R
- func NonEmpty[E any, T ~string | ~[]E, S ~[]T](ss S) S
- func Select[T any, SF SelectFunc[T], S ~[]T](ss S, selector SF) S
- func SeqIndex[T comparable, S ~[]T](ss S, seq S) int
- func StartsWith[T comparable, S ~[]T](ss S, prefix S) bool
- func Unique[T comparable, S ~[]T](s S) S
- type AccumulatorFunc
- type EqualFunc
- type KeyFunc
- type MapFunc
- type SelectFunc
Constants ¶
const MaxConcurrency = uint16(0)
Variables ¶
This section is empty.
Functions ¶
func Accumulate ¶
func Accumulate[R any, T any, AF AccumulatorFunc[T, R], S ~[]T](ss S, accumulator AF) R
Successively applies the accumulator function to each element of a slice, producing a single accumulated (reduced) result.
func AccumulateIf ¶
func AccumulateIf[R any, T any, SF SelectFunc[T], AF AccumulatorFunc[T, R], S ~[]T](ss S, selector SF, accumulator AF) R
func All ¶
func All[T any, SF SelectFunc[T], S ~[]T](ss S, selector SF) bool
func Any ¶
func Any[T any, SF SelectFunc[T], S ~[]T](ss S, selector SF) bool
func Contains ¶
func Contains[T comparable, S ~[]T](ss S, s T) bool
func Diff ¶
Computes set difference between two slices, returning a slice of elements that are in `a` but not in `b`, and a slice of elements that are in `b` but not in `a`.
func Flatten ¶
func Flatten[T any, S ~[]T, SS ~[]S](ss SS) S
Flatten takes a list of lists and puts all elements into a single list.
func GroupBy ¶
func GroupBy[S ~[]T, K comparable, KF KeyFunc[T, K], T any](ss S, keyFunc KF) map[K]S
Groups elements of a slice by a key, using a custom function to compute the key for each slice element.
func Index ¶
func Index[T comparable, S ~[]T](ss S, s T) int
Returns the index of the first occurrence of `s` in `ss`, or -1 if not found.
func IndexFunc ¶
func IndexFunc[T any, SF SelectFunc[T], S ~[]T](ss S, selector SF) int
IndexFunc returns the index of the first element that matches the selector function, or -1 if no such element is found. The name is not great, but it matches the Go standard library's `slices.IndexFunc` function.
func Intersect ¶
Intersect computes the intersection of two slices of ordered elements. It returns a new slice with elements that exist in both input slices. The resulting slice has no duplicates and elements are in sorted order.
func IntersectFunc ¶
IntersectFunc computes the intersection of two slices by using a provided function to determine if two elements are equal. It returns a new slice with elements that exist in both input slices. The resulting slice has no duplicates and preserves the order from the first slice.
func LenIf ¶
func LenIf[T any, SF SelectFunc[T], S ~[]T](ss S, selector SF) int
func MapConcurrent ¶
func MapConcurrent[R any, T any, MF MapFunc[T, R], S ~[]T](ss S, mapping MF, concurrency uint16) []R
MapConcurrent will call the mapping functions concurrently, up to specified concurrency level. If concurrency == 0 (MaxConcurrency), every function will be called using separate goroutine.
func Select ¶
func Select[T any, SF SelectFunc[T], S ~[]T](ss S, selector SF) S
func SeqIndex ¶
func SeqIndex[T comparable, S ~[]T](ss S, seq S) int
Returns the index of the first occurrence of `seq` in `ss`, or -1 if not found. This is "naive" algorithm that works well for short sequences (less than 5 elements), which is our main use case. If a need arises, we could switch this to Knuth-Morris-Pratt algorithm.
func StartsWith ¶
func StartsWith[T comparable, S ~[]T](ss S, prefix S) bool
func Unique ¶
func Unique[T comparable, S ~[]T](s S) S
Unique returns a slice with unique elements from the input slice.
Types ¶
type AccumulatorFunc ¶
The purpose of the accumulator function is to take the "accumulated so far" value (first parameter) and apply the "next element" (second parameter) to it, producing a new "accumulated so far" value. The accumulated value type and the element type can be different. It is the "reduce" operation from map-reduce pattern of large-scale data processing.
type KeyFunc ¶
type KeyFunc[T any, K comparable] interface { ~func(T) K | ~func(*T) K }