Documentation
¶
Overview ¶
Package slices provides the processing of types slices based on generics and higher-order functions.
Index ¶
- func Append(ivss ...[]V) []V
- func ContainsAll(ivs []V, pred func(v V) bool) bool
- func ContainsAny(ivs []V, pred func(v V) bool) bool
- func Copy(ivs []V) []V
- func Delete(dv V, ivs []V) []V
- func DeleteAll(dv V, ivs []V) []V
- func DeleteAllWith(ivs []V, pred func(V) bool) []V
- func DeleteFirst(ivs []V) []V
- func DeleteLast(ivs []V) []V
- func DeleteWhile(ivs []V, pred func(V) bool) []V
- func DeleteWith(ivs []V, pred func(V) bool) []V
- func Filter(ivs []V, pred func(V) bool) []V
- func FilterMap(ivs []I, fun func(I) (O, bool)) []O
- func FoldL(vs []V, acc Acc, fun func(V, Acc) Acc) Acc
- func FoldLFirst(vs []V, fun func(V, V) V) V
- func FoldR(vs []V, acc Acc, fun func(V, Acc) Acc) Acc
- func FoldRLast(vs []V, fun func(V, V) V) V
- func IsEqual(first, second []V) bool
- func IsMember(v V, ivs []V) bool
- func IsPrefix(prefix, all []V) bool
- func IsSorted(vs []V) bool
- func IsSortedWith(vs []V, less func(a, b V) bool) bool
- func IsSuffix(suffix, all []V) bool
- func Join(sep V, ivs []V) []V
- func Map(ivs []I, fun func(I) O) []O
- func MapFoldL(ivs []I, acc Acc, fun func(I, Acc) (O, Acc)) ([]O, Acc)
- func MapFoldR(ivs []I, acc Acc, fun func(I, Acc) (O, Acc)) ([]O, Acc)
- func Merge(vsa, vsb []V) []V
- func MergeWith(vsa, vsb []V, key func(V) K) []V
- func Partition(vs []V, pred func(V) bool) ([]V, []V)
- func Reverse(ivs []V) []V
- func Search(pred func(v V) bool, ivs []V) (V, bool)
- func Sort(ivs []V) []V
- func SortWith(ivs []V, less func(vs []V, i, j int) bool) []V
- func Split(n int, ivs []V) ([]V, []V)
- func SplitWith(ivs []V, pred func(V) bool) ([]V, []V)
- func Subslice(ivs []V, fpos, tpos int) []V
- func Subtract(ivs, svs []V) []V
- func TakeWhile(ivs []V, pred func(V) bool) []V
- func Unique(ivs []V) []V
- func UniqueMerge(vsa, vsb []V) []V
- func UniqueMergeWith(vsa, vsb []V, key func(V) K) []V
- func UniqueWith(ivs []V, key func(V) K) []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Append ¶
func Append[V any](ivss ...[]V) []V
Append appends the values of all slices to one new slice.
func ContainsAll ¶
ContainsAll returns true if the function pred() returns true for all values of the slice.
func ContainsAny ¶
ContainsAny returns true if the function pred() returns true for at least one value of the slice.
func Copy ¶
func Copy[V any](ivs []V) []V
Copy is simply a convenient combination of allocation and copying.
func Delete ¶
func Delete[V comparable](dv V, ivs []V) []V
Delete removes the first matching value of a slice.
func DeleteAll ¶
func DeleteAll[V comparable](dv V, ivs []V) []V
DeleteAll removes all matching valus of a slice.
func DeleteAllWith ¶
DeleteAllWith removes all values of a slice where pred returns true.
func DeleteFirst ¶ added in v0.2.0
func DeleteFirst[V any](ivs []V) []V
DeleteFirst removes the first value of a slice.
func DeleteLast ¶ added in v0.2.0
func DeleteLast[V any](ivs []V) []V
DeleteLast removes the last value of a slice.
func DeleteWhile ¶ added in v0.2.0
DeleteWhile removes all values as long pred() returns true.
func DeleteWith ¶
DeleteWith removes the first value of a slice where pred returns true.
func FilterMap ¶
FilterMap creates a slice from of new values created by fun() where it also returns true.
func FoldL ¶
func FoldL[V, Acc any](vs []V, acc Acc, fun func(V, Acc) Acc) Acc
FoldL iterates over the slice from left to right. It calls fun() for each value passing the initial accumulator. The accumulator returned by each function call is used as input at the next call. The last one will be returned.
func FoldLFirst ¶
func FoldLFirst[V any](vs []V, fun func(V, V) V) V
FoldLFirst iterates over the slice from left to right. It calls fun() for each value passing the first value as accumulator. The accumulator returned by each function call is used as input at the next call. The last one will be returned.
func FoldR ¶
func FoldR[V, Acc any](vs []V, acc Acc, fun func(V, Acc) Acc) Acc
FoldR iterates over the slice from right to left. It calls fun() for each value passing the initial accumulator. The accumulator returned by each function call is used as input at the next call. The last one will be returned.
func FoldRLast ¶
func FoldRLast[V any](vs []V, fun func(V, V) V) V
FoldRLast iterates over the slice from right to left. It calls fun() for each value passing the last value as accumulator. The accumulator returned by each function call is used as input at the next call. The last one will be returned.
func IsEqual ¶
func IsEqual[V comparable](first, second []V) bool
IsEqual returns true if both slices are equal.
func IsMember ¶
func IsMember[V comparable](v V, ivs []V) bool
IsMember returns true if the slice contains the value v.
func IsPrefix ¶
func IsPrefix[V comparable](prefix, all []V) bool
IsPrefix returns true if the first slice is the prefix of the second one.
func IsSorted ¶
func IsSorted[V constraints.Ordered](vs []V) bool
IsSorted returns true if a slice is sorted in ascending order.
func IsSortedWith ¶
IsSortedWith returns true if a slice is sorted in ascending order using less as comparison function.
func IsSuffix ¶
func IsSuffix[V comparable](suffix, all []V) bool
IsSuffix returns true if the first slice is the suffix of the second one.
func Join ¶
func Join[V any](sep V, ivs []V) []V
Join create a slice mixing a separator between each value of the slice.
func Map ¶
func Map[I, O any](ivs []I, fun func(I) O) []O
Map creates a slice of output values from the input values and converted by the map function.
func MapFoldL ¶
func MapFoldL[I, O, Acc any](ivs []I, acc Acc, fun func(I, Acc) (O, Acc)) ([]O, Acc)
MapFoldL combines the operations of Map() and FoldL() in one pass.
func MapFoldR ¶
func MapFoldR[I, O, Acc any](ivs []I, acc Acc, fun func(I, Acc) (O, Acc)) ([]O, Acc)
MapFoldR combines the operations of Map() and FoldR() in one pass.
func Merge ¶ added in v0.2.0
func Merge[V constraints.Ordered](vsa, vsb []V) []V
Merge merges two slices in a sorted way together.
func MergeWith ¶ added in v0.2.0
func MergeWith[V any, K constraints.Ordered](vsa, vsb []V, key func(V) K) []V
MergeWith merges two slices and uses a comparator function for sorting.
func Partition ¶
Partition checks all values of the slices and returns all where pred() returns true in one slice and false in another one. Their individual ordering will be the same of the original one.
func Sort ¶
func Sort[V constraints.Ordered](ivs []V) []V
Sort provides a parallel quicksort for a slice of values with the constraint ordered.
func SortWith ¶
SortWith sorts a slice based on a less function comparing the two values at the indexes i and j and returning true if the value at i has to be sorted before the one at j.
func SplitWith ¶
SplitWith returns the values while pred() returns true as first and the rest as second slice.
func Subslice ¶
Subslice returns the values of slices from fpos to tpos as a new slice. Negative fpos as well as too high tpos are allowed and will be limited. Starting behind the slice or end before 0 returns nil.
func Subtract ¶
func Subtract[V comparable](ivs, svs []V) []V
Subtract returns a new slice that is a copy of input slice, subjected to the following procedure: for each element in the subtract slice, its first occurrence in the input slice is deleted.
func Unique ¶
func Unique[V comparable](ivs []V) []V
Unique returns a slice which contains each value only once. The second and further values are dropped.
func UniqueMerge ¶ added in v0.2.0
func UniqueMerge[V constraints.Ordered](vsa, vsb []V) []V
UniqueMerge merges two slices in a sorted way together. Duplicates are dropped.
func UniqueMergeWith ¶ added in v0.2.0
func UniqueMergeWith[V any, K constraints.Ordered](vsa, vsb []V, key func(V) K) []V
UniqueMergeWith merges two slices and uses a key function to get a sortable key of the values. This could e.g. be a field of a struct. Duplicate key values are dropped.
func UniqueWith ¶
func UniqueWith[V any, K comparable](ivs []V, key func(V) K) []V
UniqueWith returns a slice which contains each value return by the key function only once. The returned value could e.g. be a fiel of a struct.
Types ¶
This section is empty.