Documentation
¶
Index ¶
- func All[E any](s []E) func(yield func(int, E) bool)
- func AppendSeq[S ~[]E, E any](s S, seq iter.Seq[E]) S
- func At[T any](s []T, index int) (r T)
- func Backward[E any](s []E) func(yield func(int, E) bool)
- func CleanFunc[E any](e []E, eq func(E, E) bool) []E
- func Clip[S ~[]E, E any](s S) S
- func Clone[S ~[]E, E any](s S) S
- func Collect[E any](seq iter.Seq[E]) []E
- func Compact[S ~[]E, E comparable](s S) S
- func CompactFunc[S ~[]E, E any](s S, eq func(E, E) bool) S
- func Compare[S ~[]E, E cmp.Ordered](s1, s2 S) int
- func CompareConv[T, R any](compare func(a, b T) int, conv func(R) (T, bool)) func(a, b R) int
- func CompareFunc[S1 ~[]E1, S2 ~[]E2, E1, E2 any](s1 S1, s2 S2, cmp func(E1, E2) int) int
- func Concat[S ~[]E, E any](ss ...S) S
- func Contains[T comparable](s []T, element T) bool
- func Delete[S ~[]E, E any](s S, i, j int) S
- func DeleteFunc[S ~[]E, E any](s S, del func(E) bool) S
- func Each[E any](s []E, eachFn func(E, int))
- func Equal[S ~[]E, E comparable](s1, s2 S) bool
- func EqualFunc[S1 ~[]E1, S2 ~[]E2, E1, E2 any](s1 S1, s2 S2, eq func(E1, E2) bool) bool
- func Filter[S ~[]V, V any](s S, predicate func(V) bool) (r S)
- func FilterMap[R, V any](s []V, predicate func(V) (R, bool)) (r []R)
- func FilterMaps[R, V any](s []V, predicate func(V, int) (R, bool)) (r []R)
- func Filters[S ~[]V, V any](s S, predicate func(V, int) bool) (r S)
- func Find[T any](s []T, predicate func(item T) bool) (r T)
- func FindOr[T comparable](s []T, predicate func(item T) bool, fallback ...T) (r T)
- func Grow[S ~[]E, E any](s S, n int) S
- func Index[T comparable](s []T, element T) int
- func IndexFilter[S ~[]V, V any](s S, predicate func(int) bool) (r S)
- func IndexFilterMap[R, V any](s []V, predicate func(int) (R, bool)) (r []R)
- func IndexFunc[S ~[]E, E any](s S, f func(E) bool) int
- func IndexMap[R, V any](s []V, predicate func(int) R) (r []R)
- func Insert[S ~[]E, E any](s S, i int, v ...E) S
- func LessConv[T, R any](less func(a, b T) bool, conv func(R) (T, bool)) func(a, b R) bool
- func Map[R, V any](s []V, predicate func(V) R) (r []R)
- func Maps[R, V any](s []V, predicate func(V, int) R) (r []R)
- func Max[S ~[]E, E cmp.Ordered](x S) E
- func MaxFunc[S ~[]E, E any](x S, cmp func(a, b E) int) E
- func Min[S ~[]E, E cmp.Ordered](x S) E
- func MinFunc[S ~[]E, E any](x S, cmp func(a, b E) int) E
- func Repeat[S ~[]E, E any](x S, count int) S
- func Replace[S ~[]E, E any](s S, i, j int, v ...E) S
- func ReplaceOrAppend[S ~[]E, E any](s S, value E, find func(E) bool) S
- func Reverse[S ~[]E, E any](s S) S
- func Some[E any](s []E, f func(E) bool) bool
- func Sort[S ~[]E, E cmp.Ordered](x S) S
- func SortFunc[S ~[]E, E any](x S, cmp func(a, b E) int) S
- func Sorted[E cmp.Ordered](seq iter.Seq[E]) []E
- func SortedFunc[E any](seq iter.Seq[E], cmp func(E, E) int) []E
- func Values[E any](s []E) func(yield func(E) bool)
- func Walk[E any](s []E, walkFn func(E, int) bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func At ¶
At returns the element at the given index. It returns the zero value if the index is out of range. if index is negative, it counts from the end of the slice.
func Backward ¶
Backward returns an iterator over index-value pairs in the slice, traversing it backward with descending indices.
func Clip ¶
func Clip[S ~[]E, E any](s S) S
Clip removes unused capacity from the slice, returning s[:len(s):len(s)].
func Clone ¶
func Clone[S ~[]E, E any](s S) S
Clone returns a copy of the slice. The elements are copied using assignment, so this is a shallow clone. The result may have additional unused capacity.
func Compact ¶
func Compact[S ~[]E, E comparable](s S) S
Compact replaces consecutive runs of equal elements with a single copy. This is like the uniq command found on Unix. Compact modifies the contents of the slice s and returns the modified slice, which may have a smaller length. Compact zeroes the elements between the new length and the original length.
func CompactFunc ¶
CompactFunc is like Compact but uses an equality function to compare elements. For runs of elements that compare equal, CompactFunc keeps the first one. CompactFunc zeroes the elements between the new length and the original length.
func Compare ¶
Compare compares the elements of s1 and s2, using cmp.Compare on each pair of elements. The elements are compared sequentially, starting at index 0, until one element is not equal to the other. The result of comparing the first non-matching elements is returned. If both slices are equal until one of them ends, the shorter slice is considered less than the longer one. The result is 0 if s1 == s2, -1 if s1 < s2, and +1 if s1 > s2.
func CompareConv ¶
func CompareFunc ¶
CompareFunc is like Compare but uses a custom comparison function on each pair of elements. The result is the first non-zero result of cmp; if cmp always returns 0 the result is 0 if len(s1) == len(s2), -1 if len(s1) < len(s2), and +1 if len(s1) > len(s2).
func Concat ¶
func Concat[S ~[]E, E any](ss ...S) S
Concat returns a new slice concatenating the passed in slices.
func Contains ¶
func Contains[T comparable](s []T, element T) bool
Contains reports whether v is present in s.
func Delete ¶
Delete removes the elements s[i:j] from s, returning the modified slice. Delete panics if j > len(s) or s[i:j] is not a valid slice of s. Delete is O(len(s)-i), so if many items must be deleted, it is better to make a single call deleting them all together than to delete one at a time. Delete zeroes the elements s[len(s)-(j-i):len(s)].
func DeleteFunc ¶
DeleteFunc removes any elements from s for which del returns true, returning the modified slice. DeleteFunc zeroes the elements between the new length and the original length.
func Equal ¶
func Equal[S ~[]E, E comparable](s1, s2 S) bool
Equal reports whether two slices are equal: the same length and all elements equal. If the lengths are different, Equal returns false. Otherwise, the elements are compared in increasing index order, and the comparison stops at the first unequal pair. Empty and nil slices are considered equal. Floating point NaNs are not considered equal.
func EqualFunc ¶
EqualFunc reports whether two slices are equal using an equality function on each pair of elements. If the lengths are different, EqualFunc returns false. Otherwise, the elements are compared in increasing index order, and the comparison stops at the first index for which eq returns false.
func FilterMaps ¶
func Find ¶
FindOrZero search an element in a slice based on a predicate. It returns the element if found or a zero value otherwise.
func FindOr ¶
func FindOr[T comparable](s []T, predicate func(item T) bool, fallback ...T) (r T)
func Grow ¶
Grow increases the slice's capacity, if necessary, to guarantee space for another n elements. After Grow(n), at least n elements can be appended to the slice without another allocation. If n is negative or too large to allocate the memory, Grow panics.
func Index ¶
func Index[T comparable](s []T, element T) int
Index returns the index of the first occurrence of v in s, or -1 if not present.
func IndexFilter ¶
func IndexFilterMap ¶
func Insert ¶
Insert inserts the values v... into s at index i, returning the modified slice. The elements at s[i:] are shifted up to make room. In the returned slice r, r[i] == v[0], and, if i < len(s), r[i+len(v)] == value originally at r[i]. Insert panics if i > len(s). This function is O(len(s) + len(v)).
func Max ¶
Max returns the maximal value in x. It panics if x is empty. For floating-point E, Max propagates NaNs (any NaN value in x forces the output to be NaN).
func MaxFunc ¶
MaxFunc returns the maximal value in x, using cmp to compare elements. It panics if x is empty. If there is more than one maximal element according to the cmp function, MaxFunc returns the first one.
func Min ¶
Min returns the minimal value in x. It panics if x is empty. For floating-point numbers, Min propagates NaNs (any NaN value in x forces the output to be NaN).
func MinFunc ¶
MinFunc returns the minimal value in x, using cmp to compare elements. It panics if x is empty. If there is more than one minimal element according to the cmp function, MinFunc returns the first one.
func Repeat ¶
Repeat returns a new slice that repeats the provided slice the given number of times. The result has length and capacity (len(x) * count). The result is never nil. Repeat panics if count is negative or if the result of (len(x) * count) overflows.
func Replace ¶
Replace replaces the elements s[i:j] by the given v, and returns the modified slice. Replace panics if j > len(s) or s[i:j] is not a valid slice of s. When len(v) < (j-i), Replace zeroes the elements between the new length and the original length.
func ReplaceOrAppend ¶
ReplaceOrAppend replaces the first element in s that satisfies find with value.
func Reverse ¶
func Reverse[S ~[]E, E any](s S) S
Reverse reverses the elements of the slice in place.
func Sort ¶
Sort sorts a slice of any ordered type in ascending order. When sorting floating-point numbers, NaNs are ordered before other values.
func SortFunc ¶
SortFunc sorts the slice x in ascending order as determined by the cmp function. This sort is not guaranteed to be stable. cmp(a, b) should return a negative number when a < b, a positive number when a > b and zero when a == b or a and b are incomparable in the sense of a strict weak ordering.
SortFunc requires that cmp is a strict weak ordering. See https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings. The function should return 0 for incomparable items.
func SortedFunc ¶
SortedFunc collects values from seq into a new slice, sorts the slice using the comparison function, and returns it.
Types ¶
This section is empty.