Documentation
¶
Overview ¶
Package slices defines various functions useful with slices of any type.
Index ¶
- func Clone[S ~[]E, E any](s S) S
- func Compact[S ~[]E, E comparable](s S) S
- func Contains[S ~[]E, E comparable](s S, v E) bool
- func ContainsFunc[S ~[]E, E any](s S, f func(E) bool) bool
- func Diff[S ~[]E, E comparable](s1, s2 S) S
- func Equal[S ~[]E, E comparable](s1, s2 S) bool
- func Index[S ~[]E, E comparable](s S, v E) int
- func IndexFunc[S ~[]E, E any](s S, f func(E) bool) int
- func Intersect[S ~[]E, E comparable](s1, s2 S) S
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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.
func Compact ¶ added in v2.1.39
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. When Compact discards m elements in total, it might not modify the elements s[len(s)-m:len(s)]. If those elements contain pointers you might consider zeroing those elements so that objects they reference can be garbage collected.
func Contains ¶
func Contains[S ~[]E, E comparable](s S, v E) bool
Contains reports whether v is present in s.
func ContainsFunc ¶
ContainsFunc reports whether at least one element e of s satisfies f(e).
func Diff ¶
func Diff[S ~[]E, E comparable](s1, s2 S) S
Diff return the difference set of s1 and s2, that is, the set of all elements that belong to s1 but not s2.
func Equal ¶ added in v2.1.39
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. Floating point NaNs are not considered equal.
func Index ¶
func Index[S ~[]E, E comparable](s S, v E) int
Index returns the index of the first occurrence of v in s, or -1 if not present.
func Intersect ¶
func Intersect[S ~[]E, E comparable](s1, s2 S) S
Intersect return the intersection set of s1 and s2, that is, the set of all elements that belong to both s1 and s2.
Types ¶
This section is empty.