Documentation ¶
Index ¶
- func Compare[T Ordered](s1, s2 []T, left, equal, right func(s T))
- func Contains[T comparable](ss []T, s T) bool
- func Find[T any, F FindFunc[T]](ss []T, funcInterface F) (elem T, found bool)
- func First[T any](ss []T) (T, bool)
- func Index[T comparable](ss []T, s T) int
- func Last[T any](ss []T) (T, bool)
- func Map[T any, R any, F MapFunc[T, R]](ss []T, funcInterface F) []R
- func Pop[T any](ss []T) (T, []T)
- func Reduce[T any](items []T, initialAccumulator T, f AccumulatorFunc[T]) T
- func Select[T any, F SelectFunc[T]](ss []T, funcInterface F) []T
- func Shift[T any](ss []T) (T, []T)
- func Sort[T Ordered](ss []T) []T
- func SortBy[T Ordered](ss []T, sortFunc func(slice []T, i, j int) bool) []T
- func SortedContains[T Ordered](ss []T, s T) bool
- func SortedIndex[T Ordered](ss []T, s T) int
- func SortedUnique[T Ordered](ss []T) []T
- func Subtract[T Ordered](s1, s2 []T) []T
- func Unique[T Ordered](ss []T) []T
- func Unshift[T any](ss []T, elem T) []T
- type AccumulatorFunc
- type FindFunc
- type MapFunc
- type Ordered
- type SelectFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compare ¶
func Compare[T Ordered](s1, s2 []T, left, equal, right func(s T))
Compare sorts and iterates s1 and s2. calling left() if the element is only in s1, right() if the element is only in s2, and equal() if it's in both. this is used as the speedy basis for other set operations.
func Contains ¶
func Contains[T comparable](ss []T, s T) bool
Contains returns true if the string is in the slice.
func First ¶
First returns the First element, or "" if there are no elements in the slice. First will also return an "ok" bool value that will be false if there were no elements to select from
func Index ¶
func Index[T comparable](ss []T, s T) int
Index returns the index of string in the slice, otherwise -1 if the string is not found.
func Last ¶
Last returns the Last element, or "" if there are no elements in the slice. Last will also return an "ok" bool value that will be false if there were no elements to select from
func Map ¶
Map over each element in the slice and perform an operation on it. the result of the operation will replace the element value. Normal func structure is func(i int, s string) string. Also accepts func structure func(s string) string
func Pop ¶
func Pop[T any](ss []T) (T, []T)
Pop pops the last element off a slice and returns the popped element and the remaining slice (note that the original slice is not modified)
func Reduce ¶
func Reduce[T any](items []T, initialAccumulator T, f AccumulatorFunc[T]) T
Reduce (aka inject) iterates over the slice of items and calls the accumulator function for each pass, storing the state in the acc variable through each pass.
func Select ¶
func Select[T any, F SelectFunc[T]](ss []T, funcInterface F) []T
func Shift ¶
func Shift[T any](ss []T) (T, []T)
Shift returns the first element and the remaining slice
func Sort ¶
func Sort[T Ordered](ss []T) []T
Sort returns a new slice that is the sorted copy of the slice it was called on. Unlike sort.Strings, it does not mutate the original slice
func SortBy ¶
SortBy returns a new, slice that is the sorted copy of the slice it was called on, using sortFunc to interpret the string as a sortable integer value. It does not mutate the original slice
func SortedContains ¶
SortedContains returns true if the string is in an already sorted slice. it's faster than Contains for large slices
func SortedIndex ¶
SortedIndex returns the index of string in the slice, otherwise -1 if the string is not found. this function will do a log2(n) binary search through the list, which is much faster for large lists. The slice must be sorted in ascending order.
func SortedUnique ¶
func SortedUnique[T Ordered](ss []T) []T
func Subtract ¶
func Subtract[T Ordered](s1, s2 []T) []T
Subtract is a set operation that returns the elements from s1 that are not in s2.