Documentation ¶
Index ¶
- func Associate[E any, K comparable, V any](slice []E, mapper func(e E) (key K, value V)) map[K]V
- func Chunk[A any](slice []A, n int) [][]A
- func Clone[E any](s []E) []E
- func Compact[A comparable](slice []A) []A
- func CompactBy[A any](slice []A, equal func(a, b A) bool) []A
- func Compare[E compare.Ordered](s1, s2 []E) int
- func CompareBy[E1, E2 any](s1 []E1, s2 []E2, cmp func(E1, E2) int) int
- func Complement[A comparable](a, b []A) []A
- func ComplementBy[A any, B comparable](by func(a A) B, a, b []A) []A
- func Concat[A any](slices ...[]A) []A
- func Contains[E comparable](s []E, needle E) bool
- func ContainsBy[E any](s []E, f func(e E) bool) bool
- func Cut[E comparable](s []E, needle E) (left, right []E, found bool)
- func CutBy[E any](s []E, on func(E) bool) (left, right []E, found bool)
- func Difference[A comparable](slices ...[]A) []A
- func DifferenceBy[A any, B comparable](by func(a A) B, slices ...[]A) []A
- func Drop[A any](slice []A, i int) []A
- func DropRight[A any](slice []A, i int) []A
- func DropRightWhile[A any](slice []A, drop func(a A) bool) []A
- func DropWhile[A any](slice []A, drop func(a A) bool) []A
- func Equal[A comparable](s1, s2 []A) bool
- func EqualBy[E1, E2 any](s1 []E1, s2 []E2, eq func(E1, E2) bool) bool
- func Every[A comparable](slice []A, needle A) bool
- func EveryBy[A any](slice []A, predicate func(A) bool) bool
- func Filter[A any](slice []A, include func(a A) bool) []A
- func Find[E any](s []E, equal func(E) bool) (e E, found bool)
- func FindLast[E any](s []E, equal func(E) bool) (e E, found bool)
- func FlatMap[A any, B any](slice []A, f func(a A) []B) []B
- func Flatten[A any](slice [][]A) []A
- func Fold[I any, A any](slice []I, combined func(accumulator A, val I) A, init A) A
- func FoldRight[I any, A any](slice []I, combined func(accumulator A, val I) A, init A) A
- func ForEach[A any](slice []A, apply func(a A))
- func ForEachRight[A any](slice []A, apply func(a A))
- func GroupBy[A any, B comparable](slice []A, key func(a A) B) map[B][]A
- func Head[A any](slice []A) (A, error)
- func Index[E comparable](s []E, needle E) int
- func IndexBy[E any](s []E, f func(E) bool) int
- func Initial[A any](slice []A) []A
- func Interleave[A any](slices ...[]A) []A
- func Intersection[A comparable](slices ...[]A) []A
- func IntersectionBy[A any, B comparable](by func(a A) B, slices ...[]A) []A
- func Join[E any](slices [][]E, glue []E) []E
- func KeyBy[A any, B comparable](slice []A, key func(a A) B) map[B]A
- func Last[A any](slice []A) (A, error)
- func LastIndex[E comparable](s []E, needle E) int
- func LastIndexBy[E any](s []E, f func(E) bool) int
- func Map[A any, B any](slice []A, f func(a A) B) []B
- func Max[E compare.Ordered](slice ...E) E
- func Min[E compare.Ordered](slice ...E) E
- func None[A comparable](slice []A, needle A) bool
- func NoneBy[A any](slice []A, predicate func(A) bool) bool
- func Nth[A any](slice []A, i int) A
- func Partition[A any](slice []A, predicate func(a A) bool) (satisfied, notSatisfied []A)
- func PartitionBy[A any, B comparable](slice []A, by func(a A) B) [][]A
- func Reject[A any](slice []A, exclude func(a A) bool) []A
- func RepeatBy[A any](i int, by func(i int) A) []A
- func Replace[E comparable](haystack []E, needle E, replacement E, n int) []E
- func ReplaceAll[E comparable](haystack []E, needle E, replacement E) []E
- func ReplaceFirst[E comparable](haystack []E, needle E, replacement E) []E
- func Reverse[A any](slice []A) []A
- func Sample[A any](slice []A, n int) []A
- func Search[A any](slice []A, f func(e A) bool) (index int, e A)
- func Set[E comparable](slice []E) map[E]bool
- func Shuffle[A any](slice []A) []A
- func SliceToMap[E any, K comparable, V any](slice []E, mapper func(a E) (key K, value V)) map[K]V
- func Some[A comparable](slice []A, needle A) bool
- func SomeBy[A any](slice []A, predicate func(A) bool) bool
- func Sort[A compare.Ordered](slice []A) []A
- func SortBy[A any](slice []A, less func(a, b A) bool) []A
- func Tail[A any](slice []A) []A
- func Take[A any](slice []A, i int) []A
- func TakeRight[A any](slice []A, i int) []A
- func TakeRightWhile[A any](slice []A, take func(a A) bool) []A
- func TakeWhile[A any](slice []A, take func(a A) bool) []A
- func Union[A comparable](slices ...[]A) []A
- func UnionBy[A any, B comparable](by func(a A) B, slices ...[]A) []A
- func Uniq[A comparable](slice []A) []A
- func UniqBy[A any, B comparable](slice []A, by func(a A) B) []A
- func Unzip[A any, B any, C any](cSlice []C, unzipper func(c C) (a A, b B)) ([]A, []B)
- func Unzip2[A any, B any, C any, D any](dSlice []D, unzipper func(d D) (a A, b B, c C)) ([]A, []B, []C)
- func Unzip3[A any, B any, C any, D any, E any](eSlice []E, unzipper func(e E) (a A, b B, c C, d D)) ([]A, []B, []C, []D)
- func Without[A comparable](slice []A, exclude ...A) []A
- func XOR[A comparable](slices ...[]A) []A
- func XORBy[A any, B comparable](by func(A) B, slices ...[]A) []A
- func Zip[A any, B any, C any](aSlice []A, bSlice []B, zipper func(a A, b B) C) []C
- func Zip2[A any, B any, C any, D any](aSlice []A, bSlice []B, cSlice []C, zipper func(a A, b B, c C) D) []D
- func Zip3[A any, B any, C any, D any, E any](aSlice []A, bSlice []B, cSlice []C, dSlice []D, ...) []E
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Associate ¶
func Associate[E any, K comparable, V any](slice []E, mapper func(e E) (key K, value V)) map[K]V
Associate will iterate over a slice turning each object into a key/value pair in a map. Alias SliceToMap
func Chunk ¶
Chunk will make de-flatten a slice into chunks eg slicez.Chunk([]int{0, 1, 2, 3, 4, 5, 6}, 2) // [][]int{{0, 1}, {2, 3}, {4, 5}, {6}}
func Compact ¶
func Compact[A comparable](slice []A) []A
Compact will remove any duplicate elements following each other in a slice, eg
{1,1,2,1,2,2,2} => {1,2,1,2}
func CompactBy ¶
CompactBy will remove any duplicate elements following each other determined by the equal func. eg removing duplicate whitespaces from a string might look like
CompactBy([]rune("a b"), func(a, b rune) { return a == ' ' && a == b })
resulting in "a b"
func Complement ¶
func Complement[A comparable](a, b []A) []A
Complement returns a slice containing all elements in "b" that is not present in "a"
func ComplementBy ¶
func ComplementBy[A any, B comparable](by func(a A) B, a, b []A) []A
ComplementBy returns a slice containing all elements in "b" that is not present in "a" determined using the "by" function
func Concat ¶
func Concat[A any](slices ...[]A) []A
Concat will concatenate supplied slices in the given order into a new slice
func Contains ¶
func Contains[E comparable](s []E, needle E) bool
Contains returns true if the needle is present in the slice
func ContainsBy ¶
ContainsBy returns true if the passed in func returns true on any of the element in the slice
func Cut ¶
func Cut[E comparable](s []E, needle E) (left, right []E, found bool)
Cut will cut a slice into a left and a right part at the first instance where the needle is found. The needle is not included
func CutBy ¶
CutBy will cut a slice into a left and a right part at the first instance where the on function returns true. The element that makes the "on" function return true will not be included.
func Difference ¶
func Difference[A comparable](slices ...[]A) []A
Difference returns a slice containing the difference between passed in slices
func DifferenceBy ¶
func DifferenceBy[A any, B comparable](by func(a A) B, slices ...[]A) []A
DifferenceBy returns a slice containing the difference between passed in slices determined by the "by" function
func Drop ¶
Drop will produce a new slice where the "i" first element of the passed in slice are removed
func DropRight ¶
DropRight will produce a new slice where the "i" last element of the passed in slice are removed
func DropRightWhile ¶
DropRightWhile will produce a new slice, where the right most elements are dropped until the first instance the "drop" function returns false
func DropWhile ¶
DropWhile will produce a new slice, where the left most elements are dropped until the first instance the "drop" function returns false
func Equal ¶
func Equal[A comparable](s1, s2 []A) bool
Equal takes two slices of that is of the interface comparable. It returns true if they are of equal length and each element in a[x] == b[x] for every element
func EqualBy ¶
EqualBy takes two slices and an equality check function. It returns true if they are of equal length and each element in eq(a[x], b[x]) == true for every element
func Every ¶
func Every[A comparable](slice []A, needle A) bool
Every returns true if every element in the slice is equal to the needle
func EveryBy ¶
EveryBy returns true if the predicate function returns true for every element in the slice
func Filter ¶
Filter will produce a new slice only containing elements where the "include" function returns true
func Find ¶
Find will find the first instance of an element in a slice where the equal func returns true
func FindLast ¶
FindLast will find the last instance of an element in a slice where the equal func returns true
func FlatMap ¶
FlatMap will map entries in one slice to entries in another slice and then flatten the map
func Fold ¶
Fold will iterate through the slice, from the left, and execute the combine function on each element accumulating the result into a value
func FoldRight ¶
FoldRight will iterate through the slice, from the right, and execute the combine function on each element accumulating the result into a value
func ForEach ¶
func ForEach[A any](slice []A, apply func(a A))
ForEach will apply the "apply" func on each element of the slice
func ForEachRight ¶
func ForEachRight[A any](slice []A, apply func(a A))
ForEachRight will apply the "apply" func on each element of the slice
func GroupBy ¶
func GroupBy[A any, B comparable](slice []A, key func(a A) B) map[B][]A
GroupBy will iterate through the slice and create a map where entries are grouped into slices using the key function generates the key .
func Head ¶
Head will return the first element of the slice, or an error if the length of the slice is 0
func Index ¶
func Index[E comparable](s []E, needle E) int
Index finds the first index of an element in an array. It returns -1 if it is not present
func IndexBy ¶
IndexBy finds the first index of an element where the passed in function returns true. It returns -1 if it is not present
func Initial ¶
func Initial[A any](slice []A) []A
Initial gets all but the last element of the slice
func Interleave ¶
func Interleave[A any](slices ...[]A) []A
Interleave Round-robin alternating input slices and sequentially appending value at index into result. interleaved := Interleave([]int{1}, []int{2, 5, 8}, []int{3, 6}, []int{4, 7, 9, 10}) []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
func Intersection ¶
func Intersection[A comparable](slices ...[]A) []A
Intersection returns a slice containing the intersection between passed in slices
func IntersectionBy ¶
func IntersectionBy[A any, B comparable](by func(a A) B, slices ...[]A) []A
IntersectionBy returns a slice containing the intersection between passed in slices determined by the "by" function
func Join ¶
func Join[E any](slices [][]E, glue []E) []E
Join will join a two-dimensional slice into a one dimensional slice with the glue slice between them. Similar to strings.Join or bytes.Join
func KeyBy ¶
func KeyBy[A any, B comparable](slice []A, key func(a A) B) map[B]A
KeyBy will iterate through the slice and create a map where the key function generates the key value pair. If multiple values generate the same key, it is the first value that is stored in the map
func Last ¶
Last will return the last element of the slice, or an error if the length of the slice is 0
func LastIndex ¶
func LastIndex[E comparable](s []E, needle E) int
LastIndex finds the last index of an element in an array. It returns -1 if it is not present
func LastIndexBy ¶
LastIndexBy finds the last index of an element where the passed in function returns true. It returns -1 if it is not present
func None ¶
func None[A comparable](slice []A, needle A) bool
None returns true if there is no element in the slice that matches the needle
func NoneBy ¶
NoneBy returns true if there are no element in the slice for which the predicate function returns true
func Nth ¶
Nth will return the nth element in the slice. It returns the zero value if len(slice) == 0. Nth looks as the slice of a modul group and will wrap around from both ends. Eg Nth(-1) will return the last element and Nth(10) where len(slice) == 10 will return the first element
func Partition ¶
Partition will partition a slice into to two slices. One where every element for which the predicate function returns true and where it returns false
func PartitionBy ¶
func PartitionBy[A any, B comparable](slice []A, by func(a A) B) [][]A
PartitionBy will partition a slice into to a slice of slices. Returns an array of elements split into groups. The order of grouped values is determined by the order they occur in collection. The grouping is generated from the results of running each element of collection through iteratee.
func Reject ¶
Reject is the complement of Filter and will produce a new slice only containing elements where the "exclude" function returns false
func RepeatBy ¶
RepeatBy creates a slice of i length and assign each element with result of the by function
func Replace ¶
func Replace[E comparable](haystack []E, needle E, replacement E, n int) []E
Replace replaces occurrences needle in haystack n times. It Replaces all for n < 0
func ReplaceAll ¶
func ReplaceAll[E comparable](haystack []E, needle E, replacement E) []E
ReplaceAll replaces all occurrences needle in haystack.
func ReplaceFirst ¶
func ReplaceFirst[E comparable](haystack []E, needle E, replacement E) []E
ReplaceFirst replaces first occurrences needle in haystack.
func Reverse ¶
func Reverse[A any](slice []A) []A
Reverse will return a news slice, but reversed of the original one
func Search ¶
Search given a slice data sorted in ascending order, the call
Search[int](data, func(e int) bool { return e >= 23 })
returns the smallest index i and element e such that e >= 23.
func Set ¶
func Set[E comparable](slice []E) map[E]bool
Set will create a Set in the form of map[E]bool, This can be used to lookup if a item was present in the slice or not
func Shuffle ¶
func Shuffle[A any](slice []A) []A
Shuffle will return a new slice where the elements from the original slice is shuffled
func SliceToMap ¶
func SliceToMap[E any, K comparable, V any](slice []E, mapper func(a E) (key K, value V)) map[K]V
SliceToMap will iterate over a slice turning each object into a key/value pair in a map
func Some ¶
func Some[A comparable](slice []A, needle A) bool
Some returns true there exist an element in the slice that is equal to the needle, an alias for Contains
func SomeBy ¶
SomeBy returns true if there is an element in the slice for which the predicate function returns true
func SortBy ¶
SortBy will return a new slice that is sorted using the supplied less function for natural ordering
func Tail ¶
func Tail[A any](slice []A) []A
Tail will return a new slice with all but the first element
func TakeRight ¶
TakeRight will produce a new slice containing the "i" last element of the passed in slice
func TakeRightWhile ¶
TakeRightWhile will produce a new slice containing all elements from the right until the "take" func returns false
func TakeWhile ¶
TakeWhile will produce a new slice containing all elements from the left until the "take" func returns false
func Union ¶
func Union[A comparable](slices ...[]A) []A
Union will return the union of an arbitrary number of slices. This is equivalent to Uniq(Concat(sliceA, sliceB))
func UnionBy ¶
func UnionBy[A any, B comparable](by func(a A) B, slices ...[]A) []A
UnionBy will return the union of an arbitrary number of slices where the by function is used to determine the key. This is equivalent to UniqBy(Concat(sliceA, sliceB), by)
func UniqBy ¶
func UniqBy[A any, B comparable](slice []A, by func(a A) B) []A
UniqBy returns a slice with no duplicate entries using the by function to determine the key
func Unzip ¶
Unzip will unzip a slice slices, c, into two slices, a and b, using the supplied unziper function
func Unzip2 ¶
func Unzip2[A any, B any, C any, D any](dSlice []D, unzipper func(d D) (a A, b B, c C)) ([]A, []B, []C)
Unzip2 will unzip a slice slices, d, into three slices, a, b and c, using the supplied unziper function
func Unzip3 ¶
func Unzip3[A any, B any, C any, D any, E any](eSlice []E, unzipper func(e E) (a A, b B, c C, d D)) ([]A, []B, []C, []D)
Unzip3 will unzip a slice slices, d, into three slices, a, b and c, using the supplied unziper function
func Without ¶
func Without[A comparable](slice []A, exclude ...A) []A
Without creates a new slice excluding all given values.
func XOR ¶
func XOR[A comparable](slices ...[]A) []A
func XORBy ¶
func XORBy[A any, B comparable](by func(A) B, slices ...[]A) []A
func Zip ¶
Zip will zip two slices, a and b, into one slice, c, using the zip function to combined elements
Types ¶
This section is empty.