Documentation ¶
Index ¶
- func All[E any](input []E, test func(E) bool) bool
- func AllEqual[S ~[]E, E comparable](value E, input S) bool
- func AllIndexed[E any](input []E, test func(int, E) bool) bool
- func AllSame[S ~[]E, E comparable](input S) bool
- func Any[E any](input []E, test func(E) bool) bool
- func AnyIndexed[E any](input []E, test func(int, E) bool) bool
- func AppendCond[E any](cond bool, slice []E, value ...E) []E
- func ContainedIn[E comparable](data []E) func(element E) bool
- func Contains[E comparable](slice []E, value E) bool
- func ContainsFunc[E any](slice []E, test func(E) bool) bool
- func ConvertToMap[E any, K comparable, V any](input []E, transform func(int, E) (K, V), resolve func(K, V, V) V) map[K]V
- func ConvertToMapKeys[K comparable, V any](input []K, transform func(int, K) V) (map[K]V, uint)
- func Create2D[E any](sizeX, sizeY uint, initial E) [][]E
- func DistinctElementCount[E comparable](data []E) map[E]uint
- func DistinctElements[E comparable](data []E) map[E]struct{}
- func Duplicate[T any](src []T) []T
- func Empty2DFrom[E, V any](prototype [][]E, initial V) [][]V
- func Empty3DFrom[E, V any](prototype [][][]E, initial V) [][][]V
- func EmptyFrom[E, V any](prototype []E, initial V) []V
- func Equal[E comparable](s1, s2 []E) bool
- func EqualFunc[E any](s1, s2 []E, test func(e1, e2 E) bool) bool
- func EqualT[E builtin.Equaler[E]](s1, s2 []E) bool
- func Extend[E any](slice []E, additions ...E) ([]E, error)
- func ExtendFrom[E any](slice []E, additions []E) ([]E, error)
- func Filter[E any](input []E, filter func(E) bool) []E
- func FilterIndexed[E any](input []E, filter func(int, E) bool) []E
- func Fold[E any, V any](input []E, initial V, fold func(V, E) V) V
- func FoldIndexed[E any, V any](input []E, initial V, fold func(V, int, E) V) V
- func ForEach[E any](data []E, process func(e E))
- func ForEachIndexed[E any](data []E, process func(idx int, e E))
- func Index[E comparable](data []E, value E) int
- func IndexFunc[E any](data []E, test func(E) bool) int
- func LastIndex[E comparable](data []E, value E) int
- func LastIndexFunc[E any](data []E, test func(E) bool) int
- func MiddleElement[E any](slice []E) (int, E, error)
- func MiddleIndex[E any](slice []E) (int, error)
- func MoveElementN[E any](input []E, idx int, n int)
- func MoveElementTo[E any](input []E, from, to int)
- func NotContainedIn[E comparable](data []E) func(e E) bool
- func Reduce[E any](input []E, reduce func(e1, e2 E) E) E
- func Reverse[E any](slice []E)
- func Reversed[E any](slice []E) []E
- func Transform[I, O any](input []I, transform func(I) O) []O
- func TransformIndexed[I, O any](input []I, transform func(int, I) O) []O
- func UniformDimensions2D[E any](slice [][]E) bool
- func Update[E any](input []E, update func(E) E)
- func UpdateIndexed[E any](input []E, update func(int, E) E)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllEqual ¶
func AllEqual[S ~[]E, E comparable](value E, input S) bool
AllEqual checks if all values in a slice are equal to the specified value.
func AllIndexed ¶
All checks if all values in a slice satisfy `test`, that is `test` returns true.
func AllSame ¶
func AllSame[S ~[]E, E comparable](input S) bool
AllSame checks if all values in a slice are the same.
func Any ¶
Any iterates over elements in the slice and tests if they satisfy `test`. Result is returned upon first element found, and will iterate over all elements if none satisfy the condition.
func AnyIndexed ¶
AnyIndexed iterates over elements in the slice and tests if they satisfy `test`. Result is returned upon first element found, and will iterate over all elements if none satisfy the condition.
func AppendCond ¶
AppendCond appends to a slice if condition holds true.
func ContainedIn ¶
func ContainedIn[E comparable](data []E) func(element E) bool
func Contains ¶
func Contains[E comparable](slice []E, value E) bool
Contains checks if provided value is present anywhere in the slice.
func ContainsFunc ¶
ContainsFunc checks any element in the slice satisfies func `test`.
func ConvertToMap ¶
func ConvertToMap[E any, K comparable, V any](input []E, transform func(int, E) (K, V), resolve func(K, V, V) V) map[K]V
ConvertToMap transforms a slice with data into a map. It assumes that there
- `transform` (mandatory), executes on each slice entry to determine key and value, used for conversion to a map.
- `resolve` (optional), resolves conflicts when multiple entries arrive at the same key in the output map. If `resolve` is nil, and a duplicate key is detected, conversion will panic.
func ConvertToMapKeys ¶
func ConvertToMapKeys[K comparable, V any](input []K, transform func(int, K) V) (map[K]V, uint)
TransformSliceToMapKeys assumes non-overlapping map keys, meaning that there will be the same number of keys in the output as there are entries in the input slice. This assumption exists to be able to detect loss of information, due to faulty logic.
Note: duplicates are not resolved. Duplicates will naturally only be represented once as keys in the map. The second return value indicates number of duplicates. This function does not provide "conflict-resolution" for duplicates. (`ConvertToMap` provides more control over the conversion process.)
Returns resulting map, count of duplicate values (present only once as map keys)
func Create2D ¶
Create2D creates a fully-allocated 2D dynamic array. FIXME function as bug (not applying initial value), but not always needed. Make this two separate functions?
func DistinctElementCount ¶
func DistinctElementCount[E comparable](data []E) map[E]uint
DistinctElementCount summarizes the contents of the slice as a multiset/bag containing each distinct element with a count for the number of occurrences. FIXME reconsider name for something shorter.
func DistinctElements ¶
func DistinctElements[E comparable](data []E) map[E]struct{}
DistinctElements summarizes the contents of the slice as a set containing each distinct element present. FIXME reconsider name for something shorter.
func Duplicate ¶
func Duplicate[T any](src []T) []T
Duplicate copies the provided source slice to new slice of same size. Copying is a shallow copy operation.
func Empty2DFrom ¶
func Empty2DFrom[E, V any](prototype [][]E, initial V) [][]V
Empty2DFrom creates an empty 2D slice with dimensions from the provided prototype.
func Empty3DFrom ¶
func Empty3DFrom[E, V any](prototype [][][]E, initial V) [][][]V
Empty3DFrom creates an empty 3D slice with dimensions from the provided prototype.
func EmptyFrom ¶
func EmptyFrom[E, V any](prototype []E, initial V) []V
EmptyFrom creates an empty (multi-dimensional) slice with initial values `initial`.
func Equal ¶
func Equal[E comparable](s1, s2 []E) bool
Equal tests the contents of two slices by pair-wise testing for equality for cases where values are comparable. FIXME needs testing
func EqualFunc ¶
EqualFunc tests equality of slices by pair-wise testing equality of elements based on `test` function. FIXME needs testing
func EqualT ¶
EqualT tests equality of slices by pair-wise testing equality of elements based on builtin.Equaler. FIXME needs testing
func Extend ¶
Extend appends to a slice within the available capacity of the slice, without reallocation.
func ExtendFrom ¶
ExtendFrom appends to a slice as far as capacity allows, without reallocation.
func Filter ¶
Filter takes a slice `input` and a function `filter`. If `filter` returns true, the value is preserved. If `filter` returns false, the value is dropped.
func FilterIndexed ¶
FilterIndexed takes a slice `input` and a function `filter`. If `filter` returns true, the value is preserved. If `filter` returns false, the value is dropped.
func Fold ¶
Fold folds a slice `input` to a single aggregate value of type `V`, using `initial V` as starting value. Function `fold` defines exactly how `V` is determined from each entry.
func FoldIndexed ¶
FoldIndexed folds a slice `input` to a single aggregate value of type `V`, using `initial V` as starting value. Function `reduce` defines exactly how `V` is determined with each entry. FoldIndexed uses callback function `fold` that receives the slice index in addition to the value.
func ForEach ¶
func ForEach[E any](data []E, process func(e E))
ForEach executes a closure for every value in `data`
func ForEachIndexed ¶
ForEachIndexed executes a closure for every value in `data`
func Index ¶
func Index[E comparable](data []E, value E) int
Index looks for a value linearly in the slice and returns its index if found, or -1 otherwise.
func IndexFunc ¶
IndexFunc looks for an element linearly in the slice and returns its index if found, or -1 otherwise. Func `test` is used to test if the value is found.
func LastIndex ¶
func LastIndex[E comparable](data []E, value E) int
LastIndex looks for an element linearly from the end and returns the index if found, which would be the last occurrence of specified value, or `-1` if not found.
func LastIndexFunc ¶
LastIndexFunc tests elements linearly from the end and returns the index of the first element that tests positively, which would be the last occurrence of a value that satisfies `test`, or `-1` if not found.
func MiddleElement ¶
TODO consider defining `ErrInvalid` error independent of `os` package
func MiddleIndex ¶
MiddleIndex looks up the middle position in an odd-sized slice and returns its index. If even-sized, it returns `0` and an `os.ErrInvalid` with context. TODO this may be too much: consider moving to different `slice` package or something, akin to `set` or `multiset` I'd guess.
func MoveElementN ¶
MoveElementN moves an element any number of positions in a slice by repeated performing in-place swaps of elements.
func MoveElementTo ¶
MoveElementTo moves an element at given index `from` in `input` to index `to`.
func NotContainedIn ¶
func NotContainedIn[E comparable](data []E) func(e E) bool
func Reduce ¶
func Reduce[E any](input []E, reduce func(e1, e2 E) E) E
Reduce reduces a slice `input` to a single element (of same type), using function `reduce`. The first input element is assumed as the initial reduction result. `reduce` is applied to the result and next input element, until the last element is processed. The reduction result is then returned.
A singleton-slice will have its first/only element as a result.
(See `Fold` for folding/"reducing" to another data-type or with special initial values.)
func Reverse ¶
func Reverse[E any](slice []E)
Reverse a slice in-place. (Calls into Go std slices.Reverse)
func Reversed ¶
func Reversed[E any](slice []E) []E
Reversed creates a new slice with the contents of provided slice in reversed order.
func Transform ¶
func Transform[I, O any](input []I, transform func(I) O) []O
Transform maps a slice of data-type `I` to a function `I -> O` and returns a result slice of data-type `O`. The result slice is immediately allocated with equal capacity to minimize allocations.
func TransformIndexed ¶
TransformIndexed maps a slice of data-type `I` to a function `idx, I -> O` and returns a result slice of data-type `O`.` The result slice is immediately allocated with equal capacity to minimize allocations.
func UniformDimensions2D ¶
func Update ¶
func Update[E any](input []E, update func(E) E)
Update updates all elements of a slice using the provided `update` func. Elements are passed in in isolation, therefore the update logic must operate on individual elements.
func UpdateIndexed ¶
UpdateIndexed updates all elements of a slice using the provided `update` func. Elements are passed in in isolation, therefore the update logic must operate on individual elements.
Types ¶
This section is empty.