Documentation ΒΆ
Index ΒΆ
- func Abs[T constraints.Integer | constraints.Float](val T) T
- func All[T any](ss []T, fn func(value T) bool) bool
- func Any[T any](ss []T, fn func(value T) bool) bool
- func AreSorted[T constraints.Ordered](ss []T) bool
- func AreUnique[T comparable](ss []T) bool
- func Average[T constraints.Integer | constraints.Float](ss []T) float64
- func Bottom[T any](ss []T, n int) (top []T)
- func Chunk[T any](ss []T, chunkLength int) [][]T
- func Compose10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R any](fn10 func(T10) R, fn9 func(T9) T10, fn8 func(T8) T9, fn7 func(T7) T8, ...) func(T1) R
- func Compose11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R any](fn11 func(T11) R, fn10 func(T10) T11, fn9 func(T9) T10, fn8 func(T8) T9, ...) func(T1) R
- func Compose12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R any](fn12 func(T12) R, fn11 func(T11) T12, fn10 func(T10) T11, fn9 func(T9) T10, ...) func(T1) R
- func Compose13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R any](fn13 func(T13) R, fn12 func(T12) T13, fn11 func(T11) T12, fn10 func(T10) T11, ...) func(T1) R
- func Compose14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R any](fn14 func(T14) R, fn13 func(T13) T14, fn12 func(T12) T13, fn11 func(T11) T12, ...) func(T1) R
- func Compose15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R any](fn15 func(T15) R, fn14 func(T14) T15, fn13 func(T13) T14, fn12 func(T12) T13, ...) func(T1) R
- func Compose16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R any](fn16 func(T16) R, fn15 func(T15) T16, fn14 func(T14) T15, fn13 func(T13) T14, ...) func(T1) R
- func Compose2[T1, T2, R any](fn2 func(T2) R, fn1 func(T1) T2) func(T1) R
- func Compose3[T1, T2, T3, R any](fn3 func(T3) R, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R
- func Compose4[T1, T2, T3, T4, R any](fn4 func(T4) R, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R
- func Compose5[T1, T2, T3, T4, T5, R any](fn5 func(T5) R, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, ...) func(T1) R
- func Compose6[T1, T2, T3, T4, T5, T6, R any](fn6 func(T6) R, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, ...) func(T1) R
- func Compose7[T1, T2, T3, T4, T5, T6, T7, R any](fn7 func(T7) R, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, ...) func(T1) R
- func Compose8[T1, T2, T3, T4, T5, T6, T7, T8, R any](fn8 func(T8) R, fn7 func(T7) T8, fn6 func(T6) T7, fn5 func(T5) T6, ...) func(T1) R
- func Compose9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](fn9 func(T9) R, fn8 func(T8) T9, fn7 func(T7) T8, fn6 func(T6) T7, ...) func(T1) R
- func Contains[T comparable](ss []T, lookingFor T) bool
- func Curry10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(...) ...
- func Curry11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(...) ...
- func Curry12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(...) ...
- func Curry13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(...) ...
- func Curry14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(...) ...
- func Curry15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(...) ...
- func Curry16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R any](...) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(...) ...
- func Curry2[T1, T2, R any](fn func(T1, T2) R) func(T1) func(T2) R
- func Curry3[T1, T2, T3, R any](fn func(T1, T2, T3) R) func(T1) func(T2) func(T3) R
- func Curry4[T1, T2, T3, T4, R any](fn func(T1, T2, T3, T4) R) func(T1) func(T2) func(T3) func(T4) R
- func Curry5[T1, T2, T3, T4, T5, R any](fn func(T1, T2, T3, T4, T5) R) func(T1) func(T2) func(T3) func(T4) func(T5) R
- func Curry6[T1, T2, T3, T4, T5, T6, R any](fn func(T1, T2, T3, T4, T5, T6) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) R
- func Curry7[T1, T2, T3, T4, T5, T6, T7, R any](fn func(T1, T2, T3, T4, T5, T6, T7) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) R
- func Curry8[T1, T2, T3, T4, T5, T6, T7, T8, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(...) ...
- func Curry9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(...) ...
- func Diff[T comparable](ss []T, against []T) (added, removed []T)
- func DropTop[T any](ss []T, n int) (drop []T)
- func DropWhile[T comparable](ss []T, f func(s T) bool) (ss2 []T)
- func Each[T any](ss []T, fn func(T)) []T
- func Equals[T comparable](ss []T, rhs []T) bool
- func Filter[T any](ss []T, condition func(T) bool) (ss2 []T)
- func FilterNot[T any](ss []T, condition func(T) bool) (ss2 []T)
- func Find[T any](ss []T, fn func(T, int) bool) T
- func First[T any](ss []T) T
- func FirstOr[T any](ss []T, defaultValue T) T
- func Flat[T any](ss [][]T) (ss2 []T)
- func Group[T comparable](ss []T) map[T]int
- func GroupBy[T comparable, U any](values []U, getKey func(U) T) map[T][]U
- func IndexOf[T any](ss []T, fn func(value T) bool) int
- func Insert[T any](ss []T, index int, values ...T) []T
- func Intersect[T comparable](ss []T, slices ...[]T) (ss2 []T)
- func JSONBytes[T constraints.Ordered](ss []T) []byte
- func JSONBytesIndent[T constraints.Ordered](ss []T, prefix, indent string) []byte
- func JSONString[T constraints.Ordered](ss []T) string
- func JSONStringIndent[T constraints.Ordered](ss []T, prefix, indent string) string
- func Keys[K comparable, V any](m map[K]V) []K
- func Last[T any](ss []T) T
- func LastOr[T any](ss []T, defaultValue T) T
- func Map[T any, U any](ss []T, fn func(T, int) U) (ss2 []U)
- func Max[T constraints.Ordered](ss []T) (min T)
- func Median[T constraints.Integer | constraints.Float](ss []T) T
- func Min[T constraints.Ordered](ss []T) (min T)
- func Mode[T comparable](ss []T) []T
- func Pop[T any](ss *[]T) (popped *T)
- func Product[T constraints.Integer | constraints.Float](ss []T) (product T)
- func Random[T constraints.Integer | constraints.Float](ss []T, source rand.Source) T
- func Reduce[IterType, AccType any](f func(acc AccType, el IterType, i int) AccType, arr []IterType, acc AccType) AccType
- func Reverse[T any](ss []T) []T
- func Send[T any](ctx context.Context, ss []T, ch chan<- T) []T
- func Sequence[T constraints.Integer | constraints.Float](ss []T, params ...int) []T
- func SequenceUsing[T any](ss []T, creator func(int) T, params ...int) []T
- func Shift[T constraints.Integer | constraints.Float](ss []T) (T, []T)
- func Shuffle[T any](ss []T, source rand.Source) []T
- func Sort[T constraints.Ordered](ss []T) []T
- func SortStableUsing[T comparable](ss []T, less func(a, b T) bool) []T
- func SortUsing[T any](ss []T, less func(a, b T) bool) []T
- func Stddev[T constraints.Integer | constraints.Float](ss []T) float64
- func SubSlice[T any](ss []T, start int, end int) (subSlice []T)
- func Sum[T constraints.Integer | constraints.Float](ss []T) (sum T)
- func Top[T any](ss []T, n int) (top []T)
- func Unique[T comparable](ss []T) []T
- func Unshift[T any](ss []T, elements ...T) (unshift []T)
- func Values[K comparable, V any](m map[K]V) []V
- type OfSlice
- func (o OfSlice[T]) All(fn func(value T) bool) bool
- func (o OfSlice[T]) Any(fn func(value T) bool) bool
- func (o OfSlice[T]) Bottom(n int) OfSlice[T]
- func (o OfSlice[T]) DropTop(n int) OfSlice[T]
- func (o OfSlice[T]) Each(fn func(T)) OfSlice[T]
- func (o OfSlice[T]) Filter(condition func(T) bool) OfSlice[T]
- func (o OfSlice[T]) FilterNot(condition func(T) bool) OfSlice[T]
- func (o OfSlice[T]) Find(fn func(T, int) bool) T
- func (o OfSlice[T]) First() T
- func (o OfSlice[T]) FirstOr(defaultValue T) T
- func (o OfSlice[T]) IndexOf(fn func(T) bool) int
- func (o OfSlice[T]) Insert(index int, values ...T) OfSlice[T]
- func (o OfSlice[T]) Join(sep string) string
- func (o OfSlice[T]) Last() T
- func (o OfSlice[T]) LastOr(defaultValue T) T
- func (o OfSlice[T]) Map(fn func(T, int) T) OfSlice[T]
- func (o OfSlice[T]) Reverse() OfSlice[T]
- func (o OfSlice[T]) Send(ctx context.Context, ch chan<- T) OfSlice[T]
- func (o OfSlice[T]) SequenceUsing(creator func(int) T, params ...int) OfSlice[T]
- func (o OfSlice[T]) Shuffle(source rand.Source) OfSlice[T]
- func (o OfSlice[T]) SortUsing(less func(a, b T) bool) OfSlice[T]
- func (o OfSlice[T]) SubSlice(start int, end int) OfSlice[T]
- func (o OfSlice[T]) Top(n int) OfSlice[T]
- func (o OfSlice[T]) Unshift(elements ...T) OfSlice[T]
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func Abs ΒΆ
func Abs[T constraints.Integer | constraints.Float](val T) T
Abs returns the absolute value.
func All ΒΆ
All will return true if all callbacks return true. It follows the same logic as the all() function in Python.
If the list is empty then true is always returned.
func Any ΒΆ
Any will return true if any callbacks return true. It follows the same logic as the any() function in Python.
If the list is empty then false is always returned.
func AreSorted ΒΆ
func AreSorted[T constraints.Ordered](ss []T) bool
AreSorted will return true if the slice is already sorted. It is a wrapper for sort.SliceIsSorted.
func AreUnique ΒΆ
func AreUnique[T comparable](ss []T) bool
AreUnique will return true if the slice contains elements that are all different (unique) from each other.
func Average ΒΆ
func Average[T constraints.Integer | constraints.Float](ss []T) float64
Average is the average of all of the elements, or zero if there are no elements.
func Bottom ΒΆ
Bottom will return n elements from bottom
that means that elements is taken from the end of the slice for this [1,2,3] slice with n == 2 will be returned [3,2] if the slice has less elements then n that'll return all elements if n < 0 it'll return empty slice.
func Chunk ΒΆ
Chunk splits the input and returns multi slices whose length equals chunkLength, except for the last slice which may contain fewer elements.
Examples:
Chunk([1, 2, 3], 4) => [ [1, 2, 3] ] Chunk([1, 2, 3], 3) => [ [1, 2, 3] ] Chunk([1, 2, 3], 2) => [ [1, 2], [3] ] Chunk([1, 2, 3], 1) => [ [1], [2], [3] ] Chunk([], 1) => [ [] ] Chunk([1, 2, 3], 0) => panic: chunkLength should be greater than 0
func Compose10 ΒΆ
func Compose10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R any](fn10 func(T10) R, fn9 func(T9) T10, fn8 func(T8) T9, fn7 func(T7) T8, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R
Performs right-to-left function composition of 10 functions
func Compose11 ΒΆ
func Compose11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R any](fn11 func(T11) R, fn10 func(T10) T11, fn9 func(T9) T10, fn8 func(T8) T9, fn7 func(T7) T8, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R
Performs right-to-left function composition of 11 functions
func Compose12 ΒΆ
func Compose12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R any](fn12 func(T12) R, fn11 func(T11) T12, fn10 func(T10) T11, fn9 func(T9) T10, fn8 func(T8) T9, fn7 func(T7) T8, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R
Performs right-to-left function composition of 12 functions
func Compose13 ΒΆ
func Compose13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R any](fn13 func(T13) R, fn12 func(T12) T13, fn11 func(T11) T12, fn10 func(T10) T11, fn9 func(T9) T10, fn8 func(T8) T9, fn7 func(T7) T8, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R
Performs right-to-left function composition of 13 functions
func Compose14 ΒΆ
func Compose14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R any](fn14 func(T14) R, fn13 func(T13) T14, fn12 func(T12) T13, fn11 func(T11) T12, fn10 func(T10) T11, fn9 func(T9) T10, fn8 func(T8) T9, fn7 func(T7) T8, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R
Performs right-to-left function composition of 14 functions
func Compose15 ΒΆ
func Compose15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R any](fn15 func(T15) R, fn14 func(T14) T15, fn13 func(T13) T14, fn12 func(T12) T13, fn11 func(T11) T12, fn10 func(T10) T11, fn9 func(T9) T10, fn8 func(T8) T9, fn7 func(T7) T8, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R
Performs right-to-left function composition of 15 functions
func Compose16 ΒΆ
func Compose16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R any](fn16 func(T16) R, fn15 func(T15) T16, fn14 func(T14) T15, fn13 func(T13) T14, fn12 func(T12) T13, fn11 func(T11) T12, fn10 func(T10) T11, fn9 func(T9) T10, fn8 func(T8) T9, fn7 func(T7) T8, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R
Performs right-to-left function composition of 16 functions
func Compose2 ΒΆ
func Compose2[T1, T2, R any](fn2 func(T2) R, fn1 func(T1) T2) func(T1) R
Performs right-to-left function composition of two functions
func Compose3 ΒΆ
func Compose3[T1, T2, T3, R any](fn3 func(T3) R, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R
Performs right-to-left function composition of three functions
func Compose4 ΒΆ
func Compose4[T1, T2, T3, T4, R any](fn4 func(T4) R, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R
Performs right-to-left function composition of four functions
func Compose5 ΒΆ
func Compose5[T1, T2, T3, T4, T5, R any](fn5 func(T5) R, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R
Performs right-to-left function composition of 5 functions
func Compose6 ΒΆ
func Compose6[T1, T2, T3, T4, T5, T6, R any](fn6 func(T6) R, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R
Performs right-to-left function composition of 6 functions
func Compose7 ΒΆ
func Compose7[T1, T2, T3, T4, T5, T6, T7, R any](fn7 func(T7) R, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R
Performs right-to-left function composition of 7 functions
func Compose8 ΒΆ
func Compose8[T1, T2, T3, T4, T5, T6, T7, T8, R any](fn8 func(T8) R, fn7 func(T7) T8, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R
Performs right-to-left function composition of 8 functions
func Compose9 ΒΆ
func Compose9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](fn9 func(T9) R, fn8 func(T8) T9, fn7 func(T7) T8, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R
Performs right-to-left function composition of 9 functions
func Contains ΒΆ
func Contains[T comparable](ss []T, lookingFor T) bool
Contains returns true if the element exists in the slice.
When using slices of pointers it will only compare by address, not value.
func Curry10 ΒΆ
func Curry10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) R
Allow to transform a function that receives 10 params in a sequence of unary functions
func Curry11 ΒΆ
func Curry11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) func(T11) R
Allow to transform a function that receives 11 params in a sequence of unary functions
func Curry12 ΒΆ
func Curry12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) func(T11) func(T12) R
Allow to transform a function that receives 12 params in a sequence of unary functions
func Curry13 ΒΆ
func Curry13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) func(T11) func(T12) func(T13) R
Allow to transform a function that receives 13 params in a sequence of unary functions
func Curry14 ΒΆ
func Curry14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) func(T11) func(T12) func(T13) func(T14) R
Allow to transform a function that receives 14 params in a sequence of unary functions
func Curry15 ΒΆ
func Curry15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) func(T11) func(T12) func(T13) func(T14) func(T15) R
Allow to transform a function that receives 15 params in a sequence of unary functions
func Curry16 ΒΆ
func Curry16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) func(T11) func(T12) func(T13) func(T14) func(T15) func(T16) R
Allow to transform a function that receives 16 params in a sequence of unary functions
func Curry2 ΒΆ
func Curry2[T1, T2, R any](fn func(T1, T2) R) func(T1) func(T2) R
Allow to transform a function that receives 2 params in a sequence of unary functions
func Curry3 ΒΆ
func Curry3[T1, T2, T3, R any](fn func(T1, T2, T3) R) func(T1) func(T2) func(T3) R
Allow to transform a function that receives 3 params in a sequence of unary functions
func Curry4 ΒΆ
func Curry4[T1, T2, T3, T4, R any](fn func(T1, T2, T3, T4) R) func(T1) func(T2) func(T3) func(T4) R
Allow to transform a function that receives 4 params in a sequence of unary functions
func Curry5 ΒΆ
func Curry5[T1, T2, T3, T4, T5, R any](fn func(T1, T2, T3, T4, T5) R) func(T1) func(T2) func(T3) func(T4) func(T5) R
Allow to transform a function that receives 5 params in a sequence of unary functions
func Curry6 ΒΆ
func Curry6[T1, T2, T3, T4, T5, T6, R any](fn func(T1, T2, T3, T4, T5, T6) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) R
Allow to transform a function that receives 6 params in a sequence of unary functions
func Curry7 ΒΆ
func Curry7[T1, T2, T3, T4, T5, T6, T7, R any](fn func(T1, T2, T3, T4, T5, T6, T7) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) R
Allow to transform a function that receives 7 params in a sequence of unary functions
func Curry8 ΒΆ
func Curry8[T1, T2, T3, T4, T5, T6, T7, T8, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) R
Allow to transform a function that receives 8 params in a sequence of unary functions
func Curry9 ΒΆ
func Curry9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) R
Allow to transform a function that receives 9 params in a sequence of unary functions
func Diff ΒΆ
func Diff[T comparable](ss []T, against []T) (added, removed []T)
Diff returns the elements that needs to be added or removed from the first slice to have the same elements in the second slice.
The order of elements is not taken into consideration, so the slices are treated sets that allow duplicate items.
The added and removed returned may be blank respectively, or contain upto as many elements that exists in the largest slice.
func DropTop ΒΆ
DropTop will return the rest slice after dropping the top n elements if the slice has less elements then n that'll return empty slice if n < 0 it'll return empty slice.
func DropWhile ΒΆ
func DropWhile[T comparable](ss []T, f func(s T) bool) (ss2 []T)
Drop items from the slice while f(item) is true. Afterwards, return every element until the slice is empty. It follows the same logic as the dropwhile() function from itertools in Python.
func Each ΒΆ
func Each[T any](ss []T, fn func(T)) []T
Each is more condensed version of Transform that allows an action to happen on each elements and pass the original slice on.
Each(cars, func (car *Car) { fmt.Printf("Car color is: %s\n", car.Color) })
Pie will not ensure immutability on items passed in so they can be manipulated, if you choose to do it this way, for example:
// Set all car colors to Red. Each(cars, func (car *Car) { car.Color = "Red" })
func Equals ΒΆ
func Equals[T comparable](ss []T, rhs []T) bool
Equals compare elements from the start to the end,
if they are the same is considered the slices are equal if all elements are the same is considered the slices are equal if each slice == nil is considered that they're equal
if element realizes Equals interface it uses that method, in other way uses default compare
func Filter ΒΆ
Filter will return a new slice containing only the elements that return true from the condition. The returned slice may contain zero elements (nil).
FilterNot works in the opposite way of Filter.
func FilterNot ΒΆ
FilterNot works the same as Filter, with a negated condition. That is, it will return a new slice only containing the elements that returned false from the condition. The returned slice may contain zero elements (nil).
func Find ΒΆ
Find will return the first element when the callback returns true or -1 if no element is found. It follows the same logic as the find() function in Javascript.
If the list is empty then -1 is always returned.
func First ΒΆ
func First[T any](ss []T) T
First returns the first element or a zero value if there are no elements.
func FirstOr ΒΆ
func FirstOr[T any](ss []T, defaultValue T) T
FirstOr returns the first element or a default value if there are no elements.
func Flat ΒΆ
func Flat[T any](ss [][]T) (ss2 []T)
Flat flattens the two-dimensional slice into one-dimensional slice. Slices of zero-length are ignored.
Examples:
Flat([[100], [101, 102], [102, 103]]) => [100, 101, 102, 102, 103] Flat([nil, [101, 102], []]) => [101, 102]
func Group ΒΆ
func Group[T comparable](ss []T) map[T]int
Group returns a map of the value with an individual count.
func GroupBy ΒΆ
func GroupBy[T comparable, U any](values []U, getKey func(U) T) map[T][]U
GroupBy groups slice elements by key returned by getKey function for each slice element.
It returns a map in which slices of elements of original slice are matched to keys defined by getKey function. It returns non-nil map, if empty or nil slice is passed.
For example, if you want to group integers by their remainder from division by 5, you can use this function as follows:
_ = GroupBy( []int{23, 76, 37, 11, 23, 47}, func(num int) int { return num % 5 }, )
In above case map {1:[76, 11], 2:[37, 47], 3:[23, 23]} is returned.
func IndexOf ΒΆ
IndexOf will return the index of the first element when the callback returns true or -1 if no element is found. It follows the same logic as the findIndex() function in Javascript.
If the list is empty then -1 is always returned.
func Intersect ΒΆ
func Intersect[T comparable](ss []T, slices ...[]T) (ss2 []T)
Intersect returns items that exist in all lists.
It returns slice without any duplicates. If zero slice arguments are provided, then nil is returned.
func JSONBytes ΒΆ
func JSONBytes[T constraints.Ordered](ss []T) []byte
JSONBytes returns the JSON encoded array as bytes.
One important thing to note is that it will treat a nil slice as an empty slice to ensure that the JSON value return is always an array.
func JSONBytesIndent ΒΆ
func JSONBytesIndent[T constraints.Ordered](ss []T, prefix, indent string) []byte
JSONBytesIndent returns the JSON encoded array as bytes with indent applied.
One important thing to note is that it will treat a nil slice as an empty slice to ensure that the JSON value return is always an array. See json.MarshalIndent for details.
func JSONString ΒΆ
func JSONString[T constraints.Ordered](ss []T) string
JSONString returns the JSON encoded array as a string.
One important thing to note is that it will treat a nil slice as an empty slice to ensure that the JSON value return is always an array.
func JSONStringIndent ΒΆ
func JSONStringIndent[T constraints.Ordered](ss []T, prefix, indent string) string
JSONStringIndent returns the JSON encoded array as a string with indent applied.
One important thing to note is that it will treat a nil slice as an empty slice to ensure that the JSON value return is always an array. See json.MarshalIndent for details.
func Keys ΒΆ
func Keys[K comparable, V any](m map[K]V) []K
Keys returns the keys in the map. All of the items will be unique.
Due to Go's randomization of iterating maps the order is not deterministic.
func Last ΒΆ
func Last[T any](ss []T) T
Last returns the last element or a zero value if there are no elements.
func LastOr ΒΆ
func LastOr[T any](ss []T, defaultValue T) T
LastOr returns the last element or a default value if there are no elements.
func Map ΒΆ
Map will return a new slice where each element has been mapped (transformed). The number of elements returned will always be the same as the input.
Be careful when using this with slices of pointers. If you modify the input value it will affect the original slice. Be sure to return a new allocated object or deep copy the existing one.
func Median ΒΆ
func Median[T constraints.Integer | constraints.Float](ss []T) T
Median returns the value separating the higher half from the lower half of a data sample.
Zero is returned if there are no elements in the slice.
If the number of elements is even, then the ElementType mean of the two "median values" is returned.
func Mode ΒΆ
func Mode[T comparable](ss []T) []T
Mode returns a new slice containing the most frequently occuring values.
The number of items returned may be the same as the input or less. It will never return zero items unless the input slice has zero items.
func Pop ΒΆ
func Pop[T any](ss *[]T) (popped *T)
Pop the first element of the slice
Usage Example:
type knownGreetings []string greetings := knownGreetings{"ciao", "hello", "hola"} for greeting := greetings.Pop(); greeting != nil; greeting = greetings.Pop() { fmt.Println(*greeting) }
func Product ΒΆ
func Product[T constraints.Integer | constraints.Float](ss []T) (product T)
Product is the product of all of the elements.
func Random ΒΆ
func Random[T constraints.Integer | constraints.Float](ss []T, source rand.Source) T
Random returns a random element by your rand.Source, or zero.
func Reduce ΒΆ
func Reduce[IterType, AccType any](f func(acc AccType, el IterType, i int) AccType, arr []IterType, acc AccType) AccType
Reduce continually applies the provided function over the slice. Reducing the elements to a single value.
Returns a zero value of T if there are no elements in the slice. It will panic if the reducer is nil and the slice has more than one element (required to invoke reduce). Otherwise returns result of applying reducer from left to right.
func Reverse ΒΆ
func Reverse[T any](ss []T) []T
Reverse returns a new copy of the slice with the elements ordered in reverse. This is useful when combined with Sort to get a descending sort order:
ss.Sort().Reverse()
func Send ΒΆ
Send sends elements to channel in normal act it sends all elements but if func canceled it can be less
it locks execution of gorutine it doesn't close channel after work returns sent elements if len(this) != len(old) considered func was canceled
func Sequence ΒΆ
func Sequence[T constraints.Integer | constraints.Float](ss []T, params ...int) []T
Sequence generates all numbers in range or returns nil if params invalid
There are 3 variations to generate:
- [0, n).
- [min, max).
- [min, max) with step.
if len(params) == 1 considered that will be returned slice between 0 and n, where n is the first param, [0, n). if len(params) == 2 considered that will be returned slice between min and max, where min is the first param, max is the second, [min, max). if len(params) > 2 considered that will be returned slice between min and max with step, where min is the first param, max is the second, step is the third one, [min, max) with step, others params will be ignored
func SequenceUsing ΒΆ
SequenceUsing generates slice in range using creator function
There are 3 variations to generate:
- [0, n).
- [min, max).
- [min, max) with step.
if len(params) == 1 considered that will be returned slice between 0 and n, where n is the first param, [0, n). if len(params) == 2 considered that will be returned slice between min and max, where min is the first param, max is the second, [min, max). if len(params) > 2 considered that will be returned slice between min and max with step, where min is the first param, max is the second, step is the third one, [min, max) with step, others params will be ignored
func Shift ΒΆ
func Shift[T constraints.Integer | constraints.Float](ss []T) (T, []T)
Shift will return two values: the shifted value and the rest slice.
func Shuffle ΒΆ
Shuffle returns a new shuffled slice by your rand.Source. The original slice is not modified.
func Sort ΒΆ
func Sort[T constraints.Ordered](ss []T) []T
Sort works similar to sort.SliceType(). However, unlike sort.SliceType the slice returned will be reallocated as to not modify the input slice.
See Reverse() and AreSorted().
func SortStableUsing ΒΆ
func SortStableUsing[T comparable](ss []T, less func(a, b T) bool) []T
SortStableUsing works similar to sort.SliceStable. However, unlike sort.SliceStable the slice returned will be reallocated as to not modify the input slice.
func SortUsing ΒΆ
SortUsing works similar to sort.Slice. However, unlike sort.Slice the slice returned will be reallocated as to not modify the input slice.
func Stddev ΒΆ
func Stddev[T constraints.Integer | constraints.Float](ss []T) float64
Stddev is the standard deviation
func SubSlice ΒΆ
SubSlice will return the subSlice from start to end(excluded)
Condition 1: If start < 0 or end < 0, nil is returned. Condition 2: If start >= end, nil is returned. Condition 3: Return all elements that exist in the range provided, if start or end is out of bounds, zero items will be placed.
func Sum ΒΆ
func Sum[T constraints.Integer | constraints.Float](ss []T) (sum T)
Sum is the sum of all of the elements.
func Top ΒΆ
Top will return n elements from head of the slice if the slice has less elements then n that'll return all elements if n < 0 it'll return empty slice.
func Unique ΒΆ
func Unique[T comparable](ss []T) []T
Unique returns a new slice with all of the unique values.
The items will be returned in a randomized order, even with the same input.
The number of items returned may be the same as the input or less. It will never return zero items unless then input slice has zero items.
A slice with zero elements is considered to be unique.
See AreUnique().
func Unshift ΒΆ
func Unshift[T any](ss []T, elements ...T) (unshift []T)
Unshift adds one or more elements to the beginning of the slice and returns the new slice.
func Values ΒΆ
func Values[K comparable, V any](m map[K]V) []V
Values returns the values in the map.
Due to Go's randomization of iterating maps the order is not deterministic.
Types ΒΆ
type OfSlice ΒΆ
type OfSlice[T any] struct { Result []T }
OfSlice provides the proxy methods that operate on slices. If the last method in the chain does not return a single value, you can access the Result to get final slice.
func (OfSlice[T]) All ΒΆ
All will return true if all callbacks return true. It follows the same logic as the all() function in Python.
If the list is empty then true is always returned.
func (OfSlice[T]) Any ΒΆ
Any will return true if any callbacks return true. It follows the same logic as the any() function in Python.
If the list is empty then false is always returned.
func (OfSlice[T]) Bottom ΒΆ
Bottom will return n elements from bottom
that means that elements is taken from the end of the slice for this [1,2,3] slice with n == 2 will be returned [3,2] if the slice has less elements then n that'll return all elements if n < 0 it'll return empty slice.
func (OfSlice[T]) DropTop ΒΆ
DropTop will return the rest slice after dropping the top n elements if the slice has less elements then n that'll return empty slice if n < 0 it'll return empty slice.
func (OfSlice[T]) Each ΒΆ
Each is more condensed version of Transform that allows an action to happen on each elements and pass the original slice on.
Each(cars, func (car *Car) { fmt.Printf("Car color is: %s\n", car.Color) })
Pie will not ensure immutability on items passed in so they can be manipulated, if you choose to do it this way, for example:
// Set all car colors to Red. Each(cars, func (car *Car) { car.Color = "Red" })
func (OfSlice[T]) Filter ΒΆ
Filter will return a new slice containing only the elements that return true from the condition. The returned slice may contain zero elements (nil).
FilterNot works in the opposite way of Filter.
func (OfSlice[T]) FilterNot ΒΆ
FilterNot works the same as Filter, with a negated condition. That is, it will return a new slice only containing the elements that returned false from the condition. The returned slice may contain zero elements (nil).
func (OfSlice[T]) First ΒΆ
func (o OfSlice[T]) First() T
First returns the first element or a zero value if there are no elements.
func (OfSlice[T]) FirstOr ΒΆ
func (o OfSlice[T]) FirstOr(defaultValue T) T
FirstOr returns the first element or a default value if there are no elements.
func (OfSlice[T]) IndexOf ΒΆ
FindFirstUsing will return the index of the first element when the callback returns true or -1 if no element is found. It follows the same logic as the findIndex() function in Javascript.
If the list is empty then -1 is always returned.
func (OfSlice[T]) Last ΒΆ
func (o OfSlice[T]) Last() T
Last returns the last element or a zero value if there are no elements.
func (OfSlice[T]) LastOr ΒΆ
func (o OfSlice[T]) LastOr(defaultValue T) T
LastOr returns the last element or a default value if there are no elements.
func (OfSlice[T]) Map ΒΆ
Map will return a new slice where each element has been mapped (transformed). The number of elements returned will always be the same as the input.
Be careful when using this with slices of pointers. If you modify the input value it will affect the original slice. Be sure to return a new allocated object or deep copy the existing one.
func (OfSlice[T]) Reverse ΒΆ
Reverse returns a new copy of the slice with the elements ordered in reverse. This is useful when combined with Sort to get a descending sort order:
ss.Sort().Reverse()
func (OfSlice[T]) Send ΒΆ
Send sends elements to channel in normal act it sends all elements but if func canceled it can be less
it locks execution of gorutine it doesn't close channel after work returns sent elements if len(this) != len(old) considered func was canceled
func (OfSlice[T]) SequenceUsing ΒΆ
SequenceUsing generates slice in range using creator function
There are 3 variations to generate:
- [0, n).
- [min, max).
- [min, max) with step.
if len(params) == 1 considered that will be returned slice between 0 and n, where n is the first param, [0, n). if len(params) == 2 considered that will be returned slice between min and max, where min is the first param, max is the second, [min, max). if len(params) > 2 considered that will be returned slice between min and max with step, where min is the first param, max is the second, step is the third one, [min, max) with step, others params will be ignored
func (OfSlice[T]) Shuffle ΒΆ
Shuffle returns a new shuffled slice by your rand.Source. The original slice is not modified.
func (OfSlice[T]) SortUsing ΒΆ
SortUsing works similar to sort.Slice. However, unlike sort.Slice the slice returned will be reallocated as to not modify the input slice.
func (OfSlice[T]) SubSlice ΒΆ
SubSlice will return the subSlice from start to end(excluded)
Condition 1: If start < 0 or end < 0, nil is returned. Condition 2: If start >= end, nil is returned. Condition 3: Return all elements that exist in the range provided, if start or end is out of bounds, zero items will be placed.
Source Files ΒΆ
- abs.go
- all.go
- any.go
- are_sorted.go
- are_unique.go
- average.go
- bottom.go
- chunk.go
- compose.go
- contains.go
- curry.go
- diff.go
- drop_top.go
- drop_while.go
- each.go
- equals.go
- filter.go
- filter_not.go
- find.go
- first.go
- first_or.go
- flat.go
- group.go
- groupby.go
- indexOf.go
- insert.go
- intersect.go
- json_bytes.go
- json_bytes_indent.go
- json_string.go
- json_string_indent.go
- keys.go
- last.go
- last_or.go
- map.go
- max.go
- median.go
- min.go
- mode.go
- of.go
- pop.go
- product.go
- random.go
- reduce.go
- reverse.go
- send.go
- sequence.go
- sequence_using.go
- shift.go
- shuffle.go
- sort.go
- sort_stable_using.go
- sort_using.go
- stddev.go
- sub_slice.go
- sum.go
- top.go
- unique.go
- unshift.go
- values.go