Documentation
ΒΆ
Index ΒΆ
- func Assign[K comparable, V any](maps ...map[K]V) map[K]V
- func Async[A any](f func() A) chan A
- func Async0(f func()) chan struct{}
- func Async1[A any](f func() A) chan A
- func Async2[A any, B any](f func() (A, B)) chan Tuple2[A, B]
- func Async3[A any, B any, C any](f func() (A, B, C)) chan Tuple3[A, B, C]
- func Async4[A any, B any, C any, D any](f func() (A, B, C, D)) chan Tuple4[A, B, C, D]
- func Async5[A any, B any, C any, D any, E any](f func() (A, B, C, D, E)) chan Tuple5[A, B, C, D, E]
- func Async6[A any, B any, C any, D any, E any, F any](f func() (A, B, C, D, E, F)) chan Tuple6[A, B, C, D, E, F]
- func Attempt(maxIteration int, f func(int) error) (int, error)
- func AttemptWithDelay(maxIteration int, delay time.Duration, f func(int, time.Duration) error) (int, time.Duration, error)
- func Chunk[T any](collection []T, size int) [][]T
- func Clamp[T constraints.Ordered](value T, min T, max T) T
- func Coalesce[T comparable](v ...T) (result T, ok bool)
- func Compact[T comparable](collection []T) []T
- func Contains[T comparable](collection []T, element T) bool
- func ContainsBy[T any](collection []T, predicate func(T) bool) bool
- func Count[T comparable](collection []T, value T) (count int)
- func CountBy[T any](collection []T, predicate func(T) bool) (count int)
- func Difference[T comparable](list1 []T, list2 []T) ([]T, []T)
- func Drop[T any](collection []T, n int) []T
- func DropRight[T any](collection []T, n int) []T
- func DropRightWhile[T any](collection []T, predicate func(T) bool) []T
- func DropWhile[T any](collection []T, predicate func(T) bool) []T
- func Empty[T any]() T
- func Every[T comparable](collection []T, subset []T) bool
- func EveryBy[V any](collection []V, predicate func(V) bool) bool
- func Fill[T Clonable[T]](collection []T, initial T) []T
- func Filter[V any](collection []V, predicate func(V, int) bool) []V
- func FilterMap[T any, R any](collection []T, callback func(T, int) (R, bool)) []R
- func Find[T any](collection []T, predicate func(T) bool) (T, bool)
- func FindIndexOf[T any](collection []T, predicate func(T) bool) (T, int, bool)
- func FindLastIndexOf[T any](collection []T, predicate func(T) bool) (T, int, bool)
- func FindOrElse[T any](collection []T, fallback T, predicate func(T) bool) T
- func FlatMap[T any, R any](collection []T, iteratee func(T, int) []R) []R
- func Flatten[T any](collection [][]T) (result []T)
- func ForEach[T any](collection []T, iteratee func(T, int))
- func FromAnySlice[T any](in []any) (out []T, ok bool)
- func FromEntries[K comparable, V any](entries []Entry[K, V]) map[K]V
- func FromPairs[K comparable, V any](entries []Entry[K, V]) map[K]V
- func FromPtr[T any](x *T) T
- func GroupBy[T any, U comparable](collection []T, iteratee func(T) U) map[U][]T
- func If[T any](condition bool, result T) *ifElse[T]
- func IfF[T any](condition bool, resultF func() T) *ifElse[T]
- func IndexOf[T comparable](collection []T, element T) int
- func Intersect[T comparable](list1 []T, list2 []T) []T
- func Invert[K comparable, V comparable](in map[K]V) map[V]K
- func IsEmpty[T comparable](v T) bool
- func KeyBy[K comparable, V any](collection []V, iteratee func(V) K) map[K]V
- func Keys[K comparable, V any](in map[K]V) []K
- func Last[T any](collection []T) (T, error)
- func LastIndexOf[T comparable](collection []T, element T) int
- func Map[T any, R any](collection []T, iteratee func(T, int) R) []R
- func MapKeys[K comparable, V any, R comparable](in map[K]V, iteratee func(V, K) R) map[R]V
- func MapValues[K comparable, V any, R any](in map[K]V, iteratee func(V, K) R) map[K]R
- func Max[T constraints.Ordered](collection []T) T
- func MaxBy[T any](collection []T, comparison func(T, T) bool) T
- func Min[T constraints.Ordered](collection []T) T
- func MinBy[T any](collection []T, comparison func(T, T) bool) T
- func Must[T any](val T, err any, messageArgs ...interface{}) T
- func Must0(err any, messageArgs ...interface{})
- func Must1[T any](val T, err any, messageArgs ...interface{}) T
- func Must2[T1 any, T2 any](val1 T1, val2 T2, err any, messageArgs ...interface{}) (T1, T2)
- func Must3[T1 any, T2 any, T3 any](val1 T1, val2 T2, val3 T3, err any, messageArgs ...interface{}) (T1, T2, T3)
- func Must4[T1 any, T2 any, T3 any, T4 any](val1 T1, val2 T2, val3 T3, val4 T4, err any, messageArgs ...interface{}) (T1, T2, T3, T4)
- func Must5[T1 any, T2 any, T3 any, T4 any, T5 any](val1 T1, val2 T2, val3 T3, val4 T4, val5 T5, err any, ...) (T1, T2, T3, T4, T5)
- func Must6[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any](val1 T1, val2 T2, val3 T3, val4 T4, val5 T5, val6 T6, err any, ...) (T1, T2, T3, T4, T5, T6)
- func NewDebounce(duration time.Duration, f ...func()) (func(), func())
- func None[V comparable](collection []V, subset []V) bool
- func NoneBy[V any](collection []V, predicate func(V) bool) bool
- func Nth[T any](collection []T, nth int) (T, error)
- func OmitBy[K comparable, V any](in map[K]V, predicate func(K, V) bool) map[K]V
- func OmitByKeys[K comparable, V any](in map[K]V, keys []K) map[K]V
- func OmitByValues[K comparable, V comparable](in map[K]V, values []V) map[K]V
- func Partial[T1, T2, R any](f func(T1, T2) R, arg1 T1) func(T2) R
- func PartitionBy[T any, K comparable](collection []T, iteratee func(x T) K) [][]T
- func PickBy[K comparable, V any](in map[K]V, predicate func(K, V) bool) map[K]V
- func PickByKeys[K comparable, V any](in map[K]V, keys []K) map[K]V
- func PickByValues[K comparable, V comparable](in map[K]V, values []V) map[K]V
- func Range(elementNum int) []int
- func RangeFrom[T constraints.Integer | constraints.Float](start T, elementNum int) []T
- func RangeWithSteps[T constraints.Integer | constraints.Float](start, end, step T) []T
- func Reduce[T any, R any](collection []T, accumulator func(R, T, int) R, initial R) R
- func Reject[V any](collection []V, predicate func(V, int) bool) []V
- func Repeat[T Clonable[T]](count int, initial T) []T
- func RepeatBy[T any](count int, predicate func(int) T) []T
- func Replace[T comparable](collection []T, old T, new T, n int) []T
- func ReplaceAll[T comparable](collection []T, old T, new T) []T
- func Reverse[T any](collection []T) []T
- func RuneLength(str string) int
- func Sample[T any](collection []T) T
- func Samples[T any](collection []T, count int) []T
- func Shuffle[T any](collection []T) []T
- func Slice[T comparable](collection []T, start int, end int) []T
- func Some[T comparable](collection []T, subset []T) bool
- func SomeBy[V any](collection []V, predicate func(V) bool) bool
- func Subset[T any](collection []T, offset int, length uint) []T
- func Substring[T ~string](str T, offset int, length uint) T
- func SumBy[T any, R constraints.Float | constraints.Integer](collection []T, iteratee func(T) R) R
- func Switch[T comparable, R any](predicate T) *switchCase[T, R]
- func Synchronize(opt ...sync.Locker) *synchronize
- func Ternary[T any](condition bool, ifOutput T, elseOutput T) T
- func Times[T any](count int, iteratee func(int) T) []T
- func ToAnySlice[T any](collection []T) []any
- func ToPtr[T any](x T) *T
- func ToSlicePtr[T any](collection []T) []*T
- func Try(callback func() error) (ok bool)
- func Try0(callback func()) bool
- func Try1[T any](callback func() error) bool
- func Try2[T any](callback func() (T, error)) bool
- func Try3[T, R any](callback func() (T, R, error)) bool
- func Try4[T, R, S any](callback func() (T, R, S, error)) bool
- func Try5[T, R, S, Q any](callback func() (T, R, S, Q, error)) bool
- func Try6[T, R, S, Q, U any](callback func() (T, R, S, Q, U, error)) bool
- func TryCatch(callback func() error, catch func())
- func TryCatchWithErrorValue(callback func() error, catch func(any))
- func TryWithErrorValue(callback func() error) (errorValue any, ok bool)
- func Union[T comparable](list1 []T, list2 []T) []T
- func Uniq[T comparable](collection []T) []T
- func UniqBy[T any, U comparable](collection []T, iteratee func(T) U) []T
- func Unpack2[A any, B any](tuple Tuple2[A, B]) (A, B)
- func Unpack3[A any, B any, C any](tuple Tuple3[A, B, C]) (A, B, C)
- func Unpack4[A any, B any, C any, D any](tuple Tuple4[A, B, C, D]) (A, B, C, D)
- func Unpack5[A any, B any, C any, D any, E any](tuple Tuple5[A, B, C, D, E]) (A, B, C, D, E)
- func Unpack6[A any, B any, C any, D any, E any, F any](tuple Tuple6[A, B, C, D, E, F]) (A, B, C, D, E, F)
- func Unpack7[A any, B any, C any, D any, E any, F any, G any](tuple Tuple7[A, B, C, D, E, F, G]) (A, B, C, D, E, F, G)
- func Unpack8[A any, B any, C any, D any, E any, F any, G any, H any](tuple Tuple8[A, B, C, D, E, F, G, H]) (A, B, C, D, E, F, G, H)
- func Unpack9[A any, B any, C any, D any, E any, F any, G any, H any, I any](tuple Tuple9[A, B, C, D, E, F, G, H, I]) (A, B, C, D, E, F, G, H, I)
- func Unzip2[A any, B any](tuples []Tuple2[A, B]) ([]A, []B)
- func Unzip3[A any, B any, C any](tuples []Tuple3[A, B, C]) ([]A, []B, []C)
- func Unzip4[A any, B any, C any, D any](tuples []Tuple4[A, B, C, D]) ([]A, []B, []C, []D)
- func Unzip5[A any, B any, C any, D any, E any](tuples []Tuple5[A, B, C, D, E]) ([]A, []B, []C, []D, []E)
- func Unzip6[A any, B any, C any, D any, E any, F any](tuples []Tuple6[A, B, C, D, E, F]) ([]A, []B, []C, []D, []E, []F)
- func Unzip7[A any, B any, C any, D any, E any, F any, G any](tuples []Tuple7[A, B, C, D, E, F, G]) ([]A, []B, []C, []D, []E, []F, []G)
- func Unzip8[A any, B any, C any, D any, E any, F any, G any, H any](tuples []Tuple8[A, B, C, D, E, F, G, H]) ([]A, []B, []C, []D, []E, []F, []G, []H)
- func Unzip9[A any, B any, C any, D any, E any, F any, G any, H any, I any](tuples []Tuple9[A, B, C, D, E, F, G, H, I]) ([]A, []B, []C, []D, []E, []F, []G, []H, []I)
- func Values[K comparable, V any](in map[K]V) []V
- type Clonable
- type Entry
- type Tuple2
- type Tuple3
- type Tuple4
- type Tuple5
- type Tuple6
- type Tuple7
- type Tuple8
- type Tuple9
- func T9[A any, B any, C any, D any, E any, F any, G any, H any, I any](a A, b B, c C, d D, e E, f F, g G, h H, i I) Tuple9[A, B, C, D, E, F, G, H, I]
- func Zip9[A any, B any, C any, D any, E any, F any, G any, H any, I any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H, i []I) []Tuple9[A, B, C, D, E, F, G, H, I]
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func Assign ΒΆ
func Assign[K comparable, V any](maps ...map[K]V) map[K]V
Assign merges multiple maps from left to right.
func Async ΒΆ added in v1.12.0
func Async[A any](f func() A) chan A
Async executes a function in a goroutine and returns the result in a channel.
func Async0 ΒΆ added in v1.17.0
func Async0(f func()) chan struct{}
Async0 executes a function in a goroutine and returns a channel set once the function finishes.
func Async2 ΒΆ added in v1.17.0
Async2 has the same behavior as Async, but returns the 2 results as a tuple inside the channel.
func Async3 ΒΆ added in v1.17.0
Async3 has the same behavior as Async, but returns the 3 results as a tuple inside the channel.
func Async4 ΒΆ added in v1.17.0
Async4 has the same behavior as Async, but returns the 4 results as a tuple inside the channel.
func Async5 ΒΆ added in v1.17.0
Async5 has the same behavior as Async, but returns the 5 results as a tuple inside the channel.
func Async6 ΒΆ added in v1.17.0
func Async6[A any, B any, C any, D any, E any, F any](f func() (A, B, C, D, E, F)) chan Tuple6[A, B, C, D, E, F]
Async6 has the same behavior as Async, but returns the 6 results as a tuple inside the channel.
func Attempt ΒΆ added in v1.5.0
Attempt invokes a function N times until it returns valid output. Returning either the caught error or nil. When first argument is less than `1`, the function runs until a successful response is returned.
func AttemptWithDelay ΒΆ added in v1.16.0
func AttemptWithDelay(maxIteration int, delay time.Duration, f func(int, time.Duration) error) (int, time.Duration, error)
AttemptWithDelay invokes a function N times until it returns valid output, with a pause between each call. Returning either the caught error or nil. When first argument is less than `1`, the function runs until a successful response is returned.
func Chunk ΒΆ
Chunk returns an array of elements split into groups the length of size. If array can't be split evenly, the final chunk will be the remaining elements.
func Clamp ΒΆ added in v1.13.0
func Clamp[T constraints.Ordered](value T, min T, max T) T
Clamp clamps number within the inclusive lower and upper bounds.
func Coalesce ΒΆ added in v1.14.0
func Coalesce[T comparable](v ...T) (result T, ok bool)
Coalesce returns the first non-empty arguments. Arguments must be comparable.
func Compact ΒΆ added in v1.22.0
func Compact[T comparable](collection []T) []T
Compact returns a slice of all non-zero elements.
func Contains ΒΆ
func Contains[T comparable](collection []T, element T) bool
Contains returns true if an element is present in a collection.
func ContainsBy ΒΆ added in v1.7.0
ContainsBy returns true if predicate function return true.
func Count ΒΆ added in v1.12.0
func Count[T comparable](collection []T, value T) (count int)
Count counts the number of elements in the collection that compare equal to value.
func CountBy ΒΆ added in v1.12.0
CountBy counts the number of elements in the collection for which predicate is true.
func Difference ΒΆ
func Difference[T comparable](list1 []T, list2 []T) ([]T, []T)
Difference returns the difference between two collections. The first value is the collection of element absent of list2. The second value is the collection of element absent of list1.
func DropRightWhile ΒΆ added in v1.9.0
DropRightWhile drops elements from the end of a slice or array while the predicate returns true.
func DropWhile ΒΆ added in v1.9.0
DropWhile drops elements from the beginning of a slice or array while the predicate returns true.
func Every ΒΆ
func Every[T comparable](collection []T, subset []T) bool
Every returns true if all elements of a subset are contained into a collection or if the subset is empty.
func EveryBy ΒΆ added in v1.18.0
EveryBy returns true if the predicate returns true for all of the elements in the collection or if the collection is empty.
func Fill ΒΆ
func Fill[T Clonable[T]](collection []T, initial T) []T
Fill fills elements of array with `initial` value.
func Filter ΒΆ
Filter iterates over elements of collection, returning an array of all elements predicate returns truthy for.
func FilterMap ΒΆ added in v1.12.0
FilterMap returns a slice which obtained after both filtering and mapping using the given callback function. The callback function should return two values:
- the result of the mapping operation and
- whether the result element should be included or not.
func Find ΒΆ
Find search an element in a slice based on a predicate. It returns element and true if element was found.
func FindIndexOf ΒΆ added in v1.12.0
FindIndexOf searches an element in a slice based on a predicate and returns the index and true. It returns -1 and false if the element is not found.
func FindLastIndexOf ΒΆ added in v1.12.0
FindLastIndexOf searches last element in a slice based on a predicate and returns the index and true. It returns -1 and false if the element is not found.
func FindOrElse ΒΆ added in v1.12.0
FindOrElse search an element in a slice based on a predicate. It returns the element if found or a given fallback value otherwise.
func FlatMap ΒΆ added in v1.7.0
FlatMap manipulates a slice and transforms and flattens it to a slice of another type.
func Flatten ΒΆ
func Flatten[T any](collection [][]T) (result []T)
Flatten returns an array a single level deep.
func FromAnySlice ΒΆ added in v1.21.0
FromAnySlice returns an `any` slice with all elements mapped to a type. Returns false in case of type conversion failure.
func FromEntries ΒΆ
func FromEntries[K comparable, V any](entries []Entry[K, V]) map[K]V
FromEntries transforms an array of key/value pairs into a map.
func FromPairs ΒΆ added in v1.22.0
func FromPairs[K comparable, V any](entries []Entry[K, V]) map[K]V
FromPairs transforms an array of key/value pairs into a map. Alias of FromEntries().
func FromPtr ΒΆ added in v1.22.0
func FromPtr[T any](x *T) T
FromPtr returns the pointer value or empty.
func GroupBy ΒΆ
func GroupBy[T any, U comparable](collection []T, iteratee func(T) U) map[U][]T
GroupBy returns an object composed of keys generated from the results of running each element of collection through iteratee.
func IndexOf ΒΆ
func IndexOf[T comparable](collection []T, element T) int
IndexOf returns the index at which the first occurrence of a value is found in an array or return -1 if the value cannot be found.
func Intersect ΒΆ
func Intersect[T comparable](list1 []T, list2 []T) []T
Intersect returns the intersection between two collections.
func Invert ΒΆ added in v1.13.0
func Invert[K comparable, V comparable](in map[K]V) map[V]K
Invert creates a map composed of the inverted keys and values. If map contains duplicate values, subsequent values overwrite property assignments of previous values.
func IsEmpty ΒΆ added in v1.22.0
func IsEmpty[T comparable](v T) bool
IsEmpty returns true if argument is a zero value.
func KeyBy ΒΆ added in v1.10.1
func KeyBy[K comparable, V any](collection []V, iteratee func(V) K) map[K]V
KeyBy transforms a slice or an array of structs to a map based on a pivot callback.
func LastIndexOf ΒΆ
func LastIndexOf[T comparable](collection []T, element T) int
LastIndexOf returns the index at which the last occurrence of a value is found in an array or return -1 if the value cannot be found.
func MapKeys ΒΆ added in v1.13.0
func MapKeys[K comparable, V any, R comparable](in map[K]V, iteratee func(V, K) R) map[R]V
MapKeys manipulates a map keys and transforms it to a map of another type.
func MapValues ΒΆ added in v1.7.0
func MapValues[K comparable, V any, R any](in map[K]V, iteratee func(V, K) R) map[K]R
MapValues manipulates a map values and transforms it to a map of another type.
func Max ΒΆ
func Max[T constraints.Ordered](collection []T) T
Max searches the maximum value of a collection.
func MaxBy ΒΆ added in v1.12.0
MaxBy search the maximum value of a collection using the given comparison function. If several values of the collection are equal to the greatest value, returns the first such value.
func Min ΒΆ
func Min[T constraints.Ordered](collection []T) T
Min search the minimum value of a collection.
func MinBy ΒΆ added in v1.12.0
MinBy search the minimum value of a collection using the given comparison function. If several values of the collection are equal to the smallest value, returns the first such value.
func Must ΒΆ added in v1.12.0
Must is a helper that wraps a call to a function returning a value and an error and panics if err is error or false.
func Must0 ΒΆ added in v1.12.0
func Must0(err any, messageArgs ...interface{})
Must0 has the same behavior than Must, but callback returns no variable.
func Must2 ΒΆ added in v1.12.0
Must2 has the same behavior than Must, but callback returns 2 variables.
func Must3 ΒΆ added in v1.12.0
func Must3[T1 any, T2 any, T3 any](val1 T1, val2 T2, val3 T3, err any, messageArgs ...interface{}) (T1, T2, T3)
Must3 has the same behavior than Must, but callback returns 3 variables.
func Must4 ΒΆ added in v1.12.0
func Must4[T1 any, T2 any, T3 any, T4 any](val1 T1, val2 T2, val3 T3, val4 T4, err any, messageArgs ...interface{}) (T1, T2, T3, T4)
Must4 has the same behavior than Must, but callback returns 4 variables.
func Must5 ΒΆ added in v1.12.0
func Must5[T1 any, T2 any, T3 any, T4 any, T5 any](val1 T1, val2 T2, val3 T3, val4 T4, val5 T5, err any, messageArgs ...interface{}) (T1, T2, T3, T4, T5)
Must5 has the same behavior than Must, but callback returns 5 variables.
func Must6 ΒΆ added in v1.12.0
func Must6[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any](val1 T1, val2 T2, val3 T3, val4 T4, val5 T5, val6 T6, err any, messageArgs ...interface{}) (T1, T2, T3, T4, T5, T6)
Must6 has the same behavior than Must, but callback returns 6 variables.
func NewDebounce ΒΆ added in v1.11.0
NewDebounce creates a debounced instance that delays invoking functions given until after wait milliseconds have elapsed.
func None ΒΆ added in v1.18.0
func None[V comparable](collection []V, subset []V) bool
None returns true if no element of a subset are contained into a collection or if the subset is empty.
func NoneBy ΒΆ added in v1.18.0
NoneBy returns true if the predicate returns true for none of the elements in the collection or if the collection is empty.
func Nth ΒΆ
Nth returns the element at index `nth` of collection. If `nth` is negative, the nth element from the end is returned. An error is returned when nth is out of slice bounds.
func OmitBy ΒΆ added in v1.13.0
func OmitBy[K comparable, V any](in map[K]V, predicate func(K, V) bool) map[K]V
OmitBy returns same map type filtered by given predicate.
func OmitByKeys ΒΆ added in v1.13.0
func OmitByKeys[K comparable, V any](in map[K]V, keys []K) map[K]V
OmitByKeys returns same map type filtered by given keys.
func OmitByValues ΒΆ added in v1.13.0
func OmitByValues[K comparable, V comparable](in map[K]V, values []V) map[K]V
OmitByValues returns same map type filtered by given values.
func Partial ΒΆ added in v1.22.0
func Partial[T1, T2, R any](f func(T1, T2) R, arg1 T1) func(T2) R
Partial returns new function that, when called, has its first argument set to the provided value.
func PartitionBy ΒΆ added in v1.4.0
func PartitionBy[T any, K comparable](collection []T, iteratee func(x T) K) [][]T
PartitionBy 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 PickBy ΒΆ added in v1.13.0
func PickBy[K comparable, V any](in map[K]V, predicate func(K, V) bool) map[K]V
PickBy returns same map type filtered by given predicate.
func PickByKeys ΒΆ added in v1.13.0
func PickByKeys[K comparable, V any](in map[K]V, keys []K) map[K]V
PickByKeys returns same map type filtered by given keys.
func PickByValues ΒΆ added in v1.13.0
func PickByValues[K comparable, V comparable](in map[K]V, values []V) map[K]V
PickByValues returns same map type filtered by given values.
func Range ΒΆ added in v1.10.0
Range creates an array of numbers (positive and/or negative) with given length.
func RangeFrom ΒΆ added in v1.10.0
func RangeFrom[T constraints.Integer | constraints.Float](start T, elementNum int) []T
RangeFrom creates an array of numbers from start with specified length.
func RangeWithSteps ΒΆ added in v1.10.0
func RangeWithSteps[T constraints.Integer | constraints.Float](start, end, step T) []T
RangeWithSteps creates an array of numbers (positive and/or negative) progressing from start up to, but not including end. step set to zero will return empty array.
func Reduce ΒΆ
Reduce reduces collection to a value which is the accumulated result of running each element in collection through accumulator, where each successive invocation is supplied the return value of the previous.
func Reject ΒΆ added in v1.11.0
Reject is the opposite of Filter, this method returns the elements of collection that predicate does not return truthy for.
func RepeatBy ΒΆ added in v1.19.0
RepeatBy builds a slice with values returned by N calls of callback.
func Replace ΒΆ added in v1.19.0
func Replace[T comparable](collection []T, old T, new T, n int) []T
Replace returns a copy of the slice with the first n non-overlapping instances of old replaced by new.
func ReplaceAll ΒΆ added in v1.19.0
func ReplaceAll[T comparable](collection []T, old T, new T) []T
ReplaceAll returns a copy of the slice with all non-overlapping instances of old replaced by new.
func Reverse ΒΆ
func Reverse[T any](collection []T) []T
Reverse reverses array so that the first element becomes the last, the second element becomes the second to last, and so on.
func RuneLength ΒΆ added in v1.19.0
RuneLength is an alias to utf8.RuneCountInString which returns the number of runes in string.
func Sample ΒΆ added in v1.6.0
func Sample[T any](collection []T) T
Sample returns a random item from collection.
func Shuffle ΒΆ
func Shuffle[T any](collection []T) []T
Shuffle returns an array of shuffled values. Uses the Fisher-Yates shuffle algorithm.
func Slice ΒΆ added in v1.22.0
func Slice[T comparable](collection []T, start int, end int) []T
Slice returns a copy of a slice from `start` up to, but not including `end`. Like `slice[start:end]`, but does not panic on overflow.
func Some ΒΆ
func Some[T comparable](collection []T, subset []T) bool
Some returns true if at least 1 element of a subset is contained into a collection. If the subset is empty Some returns false.
func SomeBy ΒΆ added in v1.18.0
SomeBy returns true if the predicate returns true for any of the elements in the collection. If the collection is empty SomeBy returns false.
func Subset ΒΆ added in v1.19.0
Subset returns a copy of a slice from `offset` up to `length` elements. Like `slice[start:start+length]`, but does not panic on overflow.
func SumBy ΒΆ added in v1.20.0
func SumBy[T any, R constraints.Float | constraints.Integer](collection []T, iteratee func(T) R) R
Summarizes the values in a collection.
func Switch ΒΆ
func Switch[T comparable, R any](predicate T) *switchCase[T, R]
Switch is a pure functional switch/case/default statement.
func Synchronize ΒΆ added in v1.20.0
Synchronize wraps the underlying callback in a mutex. It receives an optional mutex.
func Times ΒΆ added in v1.5.0
Times invokes the iteratee n times, returning an array of the results of each invocation. The iteratee is invoked with index as argument.
func ToAnySlice ΒΆ added in v1.21.0
ToAnySlice returns a slice with all elements mapped to `any` type
func ToSlicePtr ΒΆ
func ToSlicePtr[T any](collection []T) []*T
ToSlicePtr returns a slice of pointer copy of value.
func Try0 ΒΆ added in v1.11.0
func Try0(callback func()) bool
Try0 has the same behavior than Try, but callback returns no variable.
func Try2 ΒΆ added in v1.11.0
Try2 has the same behavior than Try, but callback returns 2 variables.
func Try3 ΒΆ added in v1.11.0
Try3 has the same behavior than Try, but callback returns 3 variables.
func Try4 ΒΆ added in v1.11.0
Try4 has the same behavior than Try, but callback returns 4 variables.
func Try5 ΒΆ added in v1.11.0
Try5 has the same behavior than Try, but callback returns 5 variables.
func Try6 ΒΆ added in v1.11.0
Try6 has the same behavior than Try, but callback returns 6 variables.
func TryCatch ΒΆ added in v1.11.0
func TryCatch(callback func() error, catch func())
TryCatch has the same behavior than Try, but calls the catch function in case of error.
func TryCatchWithErrorValue ΒΆ added in v1.11.0
TryCatchWithErrorValue has the same behavior than TryWithErrorValue, but calls the catch function in case of error.
func TryWithErrorValue ΒΆ added in v1.11.0
TryWithErrorValue has the same behavior than Try, but also returns value passed to panic.
func Union ΒΆ added in v1.8.0
func Union[T comparable](list1 []T, list2 []T) []T
Union returns all distinct elements from both collections. result returns will not change the order of elements relatively.
func Uniq ΒΆ
func Uniq[T comparable](collection []T) []T
Uniq returns a duplicate-free version of an array, in which only the first occurrence of each element is kept. The order of result values is determined by the order they occur in the array.
func UniqBy ΒΆ
func UniqBy[T any, U comparable](collection []T, iteratee func(T) U) []T
UniqBy returns a duplicate-free version of an array, in which only the first occurrence of each element is kept. The order of result values is determined by the order they occur in the array. It accepts `iteratee` which is invoked for each element in array to generate the criterion by which uniqueness is computed.
func Unpack6 ΒΆ added in v1.17.0
func Unpack6[A any, B any, C any, D any, E any, F any](tuple Tuple6[A, B, C, D, E, F]) (A, B, C, D, E, F)
Unpack6 returns values contained in tuple.
func Unpack7 ΒΆ added in v1.17.0
func Unpack7[A any, B any, C any, D any, E any, F any, G any](tuple Tuple7[A, B, C, D, E, F, G]) (A, B, C, D, E, F, G)
Unpack7 returns values contained in tuple.
func Unpack8 ΒΆ added in v1.17.0
func Unpack8[A any, B any, C any, D any, E any, F any, G any, H any](tuple Tuple8[A, B, C, D, E, F, G, H]) (A, B, C, D, E, F, G, H)
Unpack8 returns values contained in tuple.
func Unpack9 ΒΆ added in v1.17.0
func Unpack9[A any, B any, C any, D any, E any, F any, G any, H any, I any](tuple Tuple9[A, B, C, D, E, F, G, H, I]) (A, B, C, D, E, F, G, H, I)
Unpack9 returns values contained in tuple.
func Unzip2 ΒΆ added in v1.4.0
Unzip2 accepts an array of grouped elements and creates an array regrouping the elements to their pre-zip configuration.
func Unzip3 ΒΆ added in v1.4.0
Unzip3 accepts an array of grouped elements and creates an array regrouping the elements to their pre-zip configuration.
func Unzip4 ΒΆ added in v1.4.0
Unzip4 accepts an array of grouped elements and creates an array regrouping the elements to their pre-zip configuration.
func Unzip5 ΒΆ added in v1.4.0
func Unzip5[A any, B any, C any, D any, E any](tuples []Tuple5[A, B, C, D, E]) ([]A, []B, []C, []D, []E)
Unzip5 accepts an array of grouped elements and creates an array regrouping the elements to their pre-zip configuration.
func Unzip6 ΒΆ added in v1.4.0
func Unzip6[A any, B any, C any, D any, E any, F any](tuples []Tuple6[A, B, C, D, E, F]) ([]A, []B, []C, []D, []E, []F)
Unzip6 accepts an array of grouped elements and creates an array regrouping the elements to their pre-zip configuration.
func Unzip7 ΒΆ added in v1.4.0
func Unzip7[A any, B any, C any, D any, E any, F any, G any](tuples []Tuple7[A, B, C, D, E, F, G]) ([]A, []B, []C, []D, []E, []F, []G)
Unzip7 accepts an array of grouped elements and creates an array regrouping the elements to their pre-zip configuration.
func Unzip8 ΒΆ added in v1.4.0
func Unzip8[A any, B any, C any, D any, E any, F any, G any, H any](tuples []Tuple8[A, B, C, D, E, F, G, H]) ([]A, []B, []C, []D, []E, []F, []G, []H)
Unzip8 accepts an array of grouped elements and creates an array regrouping the elements to their pre-zip configuration.
func Unzip9 ΒΆ added in v1.4.0
func Unzip9[A any, B any, C any, D any, E any, F any, G any, H any, I any](tuples []Tuple9[A, B, C, D, E, F, G, H, I]) ([]A, []B, []C, []D, []E, []F, []G, []H, []I)
Unzip9 accepts an array of grouped elements and creates an array regrouping the elements to their pre-zip configuration.
func Values ΒΆ
func Values[K comparable, V any](in map[K]V) []V
Values creates an array of the map values.
Types ΒΆ
type Clonable ΒΆ
type Clonable[T any] interface { Clone() T }
Clonable defines a constraint of types having Clone() T method.
type Entry ΒΆ
type Entry[K comparable, V any] struct { Key K Value V }
Entry defines a key/value pairs.
func Entries ΒΆ
func Entries[K comparable, V any](in map[K]V) []Entry[K, V]
Entries transforms a map into array of key/value pairs.
func ToPairs ΒΆ added in v1.22.0
func ToPairs[K comparable, V any](in map[K]V) []Entry[K, V]
ToPairs transforms a map into array of key/value pairs. Alias of Entries().
type Tuple2 ΒΆ added in v1.4.0
Tuple2 is a group of 2 elements (pair).
func Zip2 ΒΆ added in v1.4.0
Zip2 creates a slice of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on. When collections have different size, the Tuple attributes are filled with zero value.
type Tuple3 ΒΆ added in v1.4.0
Tuple3 is a group of 3 elements.
func Zip3 ΒΆ added in v1.4.0
Zip3 creates a slice of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on. When collections have different size, the Tuple attributes are filled with zero value.
type Tuple4 ΒΆ added in v1.4.0
Tuple4 is a group of 4 elements.
func Zip4 ΒΆ added in v1.4.0
Zip4 creates a slice of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on. When collections have different size, the Tuple attributes are filled with zero value.
type Tuple5 ΒΆ added in v1.4.0
Tuple5 is a group of 5 elements.
func Zip5 ΒΆ added in v1.4.0
func Zip5[A any, B any, C any, D any, E any](a []A, b []B, c []C, d []D, e []E) []Tuple5[A, B, C, D, E]
Zip5 creates a slice of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on. When collections have different size, the Tuple attributes are filled with zero value.
type Tuple6 ΒΆ added in v1.4.0
Tuple6 is a group of 6 elements.
func T6 ΒΆ added in v1.13.0
func T6[A any, B any, C any, D any, E any, F any](a A, b B, c C, d D, e E, f F) Tuple6[A, B, C, D, E, F]
T6 creates a tuple from a list of values.
func Zip6 ΒΆ added in v1.4.0
func Zip6[A any, B any, C any, D any, E any, F any](a []A, b []B, c []C, d []D, e []E, f []F) []Tuple6[A, B, C, D, E, F]
Zip6 creates a slice of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on. When collections have different size, the Tuple attributes are filled with zero value.
type Tuple7 ΒΆ added in v1.4.0
Tuple7 is a group of 7 elements.
func T7 ΒΆ added in v1.13.0
func T7[A any, B any, C any, D any, E any, F any, G any](a A, b B, c C, d D, e E, f F, g G) Tuple7[A, B, C, D, E, F, G]
T7 creates a tuple from a list of values.
func Zip7 ΒΆ added in v1.4.0
func Zip7[A any, B any, C any, D any, E any, F any, G any](a []A, b []B, c []C, d []D, e []E, f []F, g []G) []Tuple7[A, B, C, D, E, F, G]
Zip7 creates a slice of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on. When collections have different size, the Tuple attributes are filled with zero value.
type Tuple8 ΒΆ added in v1.4.0
type Tuple8[A any, B any, C any, D any, E any, F any, G any, H any] struct { A A B B C C D D E E F F G G H H }
Tuple8 is a group of 8 elements.
func T8 ΒΆ added in v1.13.0
func T8[A any, B any, C any, D any, E any, F any, G any, H any](a A, b B, c C, d D, e E, f F, g G, h H) Tuple8[A, B, C, D, E, F, G, H]
T8 creates a tuple from a list of values.
func Zip8 ΒΆ added in v1.4.0
func Zip8[A any, B any, C any, D any, E any, F any, G any, H any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H) []Tuple8[A, B, C, D, E, F, G, H]
Zip8 creates a slice of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on. When collections have different size, the Tuple attributes are filled with zero value.
type Tuple9 ΒΆ added in v1.4.0
type Tuple9[A any, B any, C any, D any, E any, F any, G any, H any, I any] struct { A A B B C C D D E E F F G G H H I I }
Tuple9 is a group of 9 elements.
func T9 ΒΆ added in v1.13.0
func T9[A any, B any, C any, D any, E any, F any, G any, H any, I any](a A, b B, c C, d D, e E, f F, g G, h H, i I) Tuple9[A, B, C, D, E, F, G, H, I]
T8 creates a tuple from a list of values.
func Zip9 ΒΆ added in v1.4.0
func Zip9[A any, B any, C any, D any, E any, F any, G any, H any, I any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H, i []I) []Tuple9[A, B, C, D, E, F, G, H, I]
Zip9 creates a slice of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on. When collections have different size, the Tuple attributes are filled with zero value.