Documentation
ΒΆ
Index ΒΆ
- Variables
- func Assign(maps ...map[K]V) map[K]V
- func Associate(collection []T, transform func(item T) (K, V)) map[K]V
- func Async(f func() A) <-chan A
- func Async0(f func()) <-chan struct{}
- func Async1(f func() A) <-chan A
- func Async2(f func() (A, B)) <-chan Tuple2[A, B]
- func Async3(f func() (A, B, C)) <-chan Tuple3[A, B, C]
- func Async4(f func() (A, B, C, D)) <-chan Tuple4[A, B, C, D]
- func Async5(f func() (A, B, C, D, E)) <-chan Tuple5[A, B, C, D, E]
- func Async6(f func() (A, B, C, D, E, F)) <-chan Tuple6[A, B, C, D, E, F]
- func Attempt(maxIteration int, f func(index int) error) (int, error)
- func AttemptWhile(maxIteration int, f func(int) (error, bool)) (int, error)
- func AttemptWhileWithDelay(maxIteration int, delay time.Duration, ...) (int, time.Duration, error)
- func AttemptWithDelay(maxIteration int, delay time.Duration, ...) (int, time.Duration, error)
- func Batch(ch <-chan T, size int) (collection []T, length int, readTime time.Duration, ok bool)deprecated
- func BatchWithTimeout(ch <-chan T, size int, timeout time.Duration) (collection []T, length int, readTime time.Duration, ok bool)deprecated
- func Buffer(ch <-chan T, size int) (collection []T, length int, readTime time.Duration, ok bool)
- func BufferWithTimeout(ch <-chan T, size int, timeout time.Duration) (collection []T, length int, readTime time.Duration, ok bool)
- func ChannelDispatcher(stream <-chan T, count int, channelBufferCap int, ...) []<-chan T
- func ChannelMerge(channelBufferCap int, upstreams ...<-chan T) <-chan Tdeprecated
- func ChannelToSlice(ch <-chan T) []T
- func Chunk(collection []T, size int) [][]T
- func ChunkString(str T, size int) []T
- func Clamp(value T, min T, max T) T
- func Coalesce(v ...T) (result T, ok bool)
- func Compact(collection []T) []T
- func Contains(collection []T, element T) bool
- func ContainsBy(collection []T, predicate func(item T) bool) bool
- func Count(collection []T, value T) (count int)
- func CountBy(collection []T, predicate func(item T) bool) (count int)
- func CountValues(collection []T) map[T]int
- func CountValuesBy(collection []T, mapper func(item T) U) map[U]int
- func Difference(list1 []T, list2 []T) ([]T, []T)
- func DispatchingStrategyFirst(msg T, index uint64, channels []<-chan T) int
- func DispatchingStrategyLeast(msg T, index uint64, channels []<-chan T) int
- func DispatchingStrategyMost(msg T, index uint64, channels []<-chan T) int
- func DispatchingStrategyRandom(msg T, index uint64, channels []<-chan T) int
- func DispatchingStrategyRoundRobin(msg T, index uint64, channels []<-chan T) int
- func Drop(collection []T, n int) []T
- func DropRight(collection []T, n int) []T
- func DropRightWhile(collection []T, predicate func(item T) bool) []T
- func DropWhile(collection []T, predicate func(item T) bool) []T
- func Empty() T
- func EmptyableToPtr(x T) *T
- func ErrorsAs(err error) (T, bool)
- func Every(collection []T, subset []T) bool
- func EveryBy(collection []T, predicate func(item T) bool) bool
- func FanIn(channelBufferCap int, upstreams ...<-chan T) <-chan T
- func FanOut(count int, channelsBufferCap int, upstream <-chan T) []<-chan T
- func Fill(collection []T, initial T) []T
- func Filter(collection []V, predicate func(item V, index int) bool) []V
- func FilterMap(collection []T, callback func(item T, index int) (R, bool)) []R
- func Find(collection []T, predicate func(item T) bool) (T, bool)
- func FindDuplicates(collection []T) []T
- func FindDuplicatesBy(collection []T, iteratee func(item T) U) []T
- func FindIndexOf(collection []T, predicate func(item T) bool) (T, int, bool)
- func FindKey(object map[K]V, value V) (K, bool)
- func FindKeyBy(object map[K]V, predicate func(key K, value V) bool) (K, bool)
- func FindLastIndexOf(collection []T, predicate func(item T) bool) (T, int, bool)
- func FindOrElse(collection []T, fallback T, predicate func(item T) bool) T
- func FindUniques(collection []T) []T
- func FindUniquesBy(collection []T, iteratee func(item T) U) []T
- func FlatMap(collection []T, iteratee func(item T, index int) []R) []R
- func Flatten(collection [][]T) []T
- func ForEach(collection []T, iteratee func(item T, index int))
- func FromAnySlice(in []any) (out []T, ok bool)
- func FromEntries(entries []Entry[K, V]) map[K]V
- func FromPairs(entries []Entry[K, V]) map[K]V
- func FromPtr(x *T) T
- func FromPtrOr(x *T, fallback T) T
- func Generator(bufferSize int, generator func(yield func(T))) <-chan T
- func GroupBy(collection []T, iteratee func(item T) U) map[U][]T
- func If(condition bool, result T) *ifElse[T]
- func IfF(condition bool, resultF func() T) *ifElse[T]
- func IndexOf(collection []T, element T) int
- func Interleave(collections ...[]T) []T
- func Intersect(list1 []T, list2 []T) []T
- func Invert(in map[K]V) map[V]K
- func IsEmpty(v T) bool
- func IsNotEmpty(v T) bool
- func IsSorted(collection []T) bool
- func IsSortedByKey(collection []T, iteratee func(item T) K) bool
- func KeyBy(collection []V, iteratee func(item V) K) map[K]V
- func Keys(in map[K]V) []K
- func Last(collection []T) (T, error)
- func LastIndexOf(collection []T, element T) int
- func Map(collection []T, iteratee func(item T, index int) R) []R
- func MapEntries(in map[K1]V1, iteratee func(key K1, value V1) (K2, V2)) map[K2]V2
- func MapKeys(in map[K]V, iteratee func(value V, key K) R) map[R]V
- func MapToSlice(in map[K]V, iteratee func(key K, value V) R) []R
- func MapValues(in map[K]V, iteratee func(value V, key K) R) map[K]R
- func Max(collection []T) T
- func MaxBy(collection []T, comparison func(a T, b T) bool) T
- func Min(collection []T) T
- func MinBy(collection []T, comparison func(a T, b T) bool) T
- func Must(val T, err any, messageArgs ...interface{}) T
- func Must0(err any, messageArgs ...interface{})
- func Must1(val T, err any, messageArgs ...interface{}) T
- func Must2(val1 T1, val2 T2, err any, messageArgs ...interface{}) (T1, T2)
- func Must3(val1 T1, val2 T2, val3 T3, err any, messageArgs ...interface{}) (T1, T2, T3)
- func Must4(val1 T1, val2 T2, val3 T3, val4 T4, err any, messageArgs ...interface{}) (T1, T2, T3, T4)
- func Must5(val1 T1, val2 T2, val3 T3, val4 T4, val5 T5, err any, ...) (T1, T2, T3, T4, T5)
- func Must6(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 NewDebounceBy(duration time.Duration, f ...func(key T, count int)) (func(key T), func(key T))
- func None(collection []T, subset []T) bool
- func NoneBy(collection []T, predicate func(item T) bool) bool
- func Nth(collection []T, nth N) (T, error)
- func OmitBy(in map[K]V, predicate func(key K, value V) bool) map[K]V
- func OmitByKeys(in map[K]V, keys []K) map[K]V
- func OmitByValues(in map[K]V, values []V) map[K]V
- func Partial(f func(a T1, b T2) R, arg1 T1) func(T2) R
- func Partial1(f func(T1, T2) R, arg1 T1) func(T2) R
- func Partial2(f func(T1, T2, T3) R, arg1 T1) func(T2, T3) R
- func Partial3(f func(T1, T2, T3, T4) R, arg1 T1) func(T2, T3, T4) R
- func Partial4(f func(T1, T2, T3, T4, T5) R, arg1 T1) func(T2, T3, T4, T5) R
- func Partial5(f func(T1, T2, T3, T4, T5, T6) R, arg1 T1) func(T2, T3, T4, T5, T6) R
- func PartitionBy(collection []T, iteratee func(item T) K) [][]T
- func PickBy(in map[K]V, predicate func(key K, value V) bool) map[K]V
- func PickByKeys(in map[K]V, keys []K) map[K]V
- func PickByValues(in map[K]V, values []V) map[K]V
- func RandomString(size int, charset []rune) string
- func Range(elementNum int) []int
- func RangeFrom(start T, elementNum int) []T
- func RangeWithSteps(start, end, step T) []T
- func Reduce(collection []T, accumulator func(agg R, item T, index int) R, initial R) R
- func ReduceRight(collection []T, accumulator func(agg R, item T, index int) R, initial R) R
- func Reject(collection []V, predicate func(item V, index int) bool) []V
- func Repeat(count int, initial T) []T
- func RepeatBy(count int, predicate func(index int) T) []T
- func Replace(collection []T, old T, new T, n int) []T
- func ReplaceAll(collection []T, old T, new T) []T
- func Reverse(collection []T) []T
- func RuneLength(str string) int
- func Sample(collection []T) T
- func Samples(collection []T, count int) []T
- func Shuffle(collection []T) []T
- func Slice(collection []T, start int, end int) []T
- func SliceToChannel(bufferSize int, collection []T) <-chan T
- func SliceToMap(collection []T, transform func(item T) (K, V)) map[K]V
- func Some(collection []T, subset []T) bool
- func SomeBy(collection []T, predicate func(item T) bool) bool
- func Subset(collection []T, offset int, length uint) []T
- func Substring(str T, offset int, length uint) T
- func Sum(collection []T) T
- func SumBy(collection []T, iteratee func(item T) R) R
- func Switch(predicate T) *switchCase[T, R]
- func Synchronize(opt ...sync.Locker) *synchronize
- func Ternary(condition bool, ifOutput T, elseOutput T) T
- func TernaryF(condition bool, ifFunc func() T, elseFunc func() T) T
- func Times(count int, iteratee func(index int) T) []T
- func ToAnySlice(collection []T) []any
- func ToPtr(x T) *T
- func ToSlicePtr(collection []T) []*T
- func Try(callback func() error) (ok bool)
- func Try0(callback func()) bool
- func Try1(callback func() error) bool
- func Try2(callback func() (T, error)) bool
- func Try3(callback func() (T, R, error)) bool
- func Try4(callback func() (T, R, S, error)) bool
- func Try5(callback func() (T, R, S, Q, error)) bool
- func Try6(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 TryOr(callback func() (A, error), fallbackA A) (A, bool)
- func TryOr1(callback func() (A, error), fallbackA A) (A, bool)
- func TryOr2(callback func() (A, B, error), fallbackA A, fallbackB B) (A, B, bool)
- func TryOr3(callback func() (A, B, C, error), fallbackA A, fallbackB B, fallbackC C) (A, B, C, bool)
- func TryOr4(callback func() (A, B, C, D, error), fallbackA A, fallbackB B, fallbackC C, ...) (A, B, C, D, bool)
- func TryOr5(callback func() (A, B, C, D, E, error), fallbackA A, fallbackB B, fallbackC C, ...) (A, B, C, D, E, bool)
- func TryOr6(callback func() (A, B, C, D, E, F, error), fallbackA A, fallbackB B, ...) (A, B, C, D, E, F, bool)
- func TryWithErrorValue(callback func() error) (errorValue any, ok bool)
- func Union(lists ...[]T) []T
- func Uniq(collection []T) []T
- func UniqBy(collection []T, iteratee func(item T) U) []T
- func Unpack2(tuple Tuple2[A, B]) (A, B)
- func Unpack3(tuple Tuple3[A, B, C]) (A, B, C)
- func Unpack4(tuple Tuple4[A, B, C, D]) (A, B, C, D)
- func Unpack5(tuple Tuple5[A, B, C, D, E]) (A, B, C, D, E)
- func Unpack6(tuple Tuple6[A, B, C, D, E, F]) (A, B, C, D, E, F)
- func Unpack7(tuple Tuple7[A, B, C, D, E, F, G]) (A, B, C, D, E, F, G)
- func Unpack8(tuple Tuple8[A, B, C, D, E, F, G, H]) (A, B, C, D, E, F, G, H)
- func Unpack9(tuple Tuple9[A, B, C, D, E, F, G, H, I]) (A, B, C, D, E, F, G, H, I)
- func Unzip2(tuples []Tuple2[A, B]) ([]A, []B)
- func Unzip3(tuples []Tuple3[A, B, C]) ([]A, []B, []C)
- func Unzip4(tuples []Tuple4[A, B, C, D]) ([]A, []B, []C, []D)
- func Unzip5(tuples []Tuple5[A, B, C, D, E]) ([]A, []B, []C, []D, []E)
- func Unzip6(tuples []Tuple6[A, B, C, D, E, F]) ([]A, []B, []C, []D, []E, []F)
- func Unzip7(tuples []Tuple7[A, B, C, D, E, F, G]) ([]A, []B, []C, []D, []E, []F, []G)
- func Unzip8(tuples []Tuple8[A, B, C, D, E, F, G, H]) ([]A, []B, []C, []D, []E, []F, []G, []H)
- func Unzip9(tuples []Tuple9[A, B, C, D, E, F, G, H, I]) ([]A, []B, []C, []D, []E, []F, []G, []H, []I)
- func Validate(ok bool, format string, args ...any) error
- func ValueOr(in map[K]V, key K, fallback V) V
- func Values(in map[K]V) []V
- func Without(collection []T, exclude ...T) []T
- func WithoutEmpty(collection []T) []T
- type Clonable
- type DispatchingStrategy
- type Entry
- type Transaction
- type Tuple2
- type Tuple3
- type Tuple4
- type Tuple5
- type Tuple6
- type Tuple7
- type Tuple8
- type Tuple9
Constants ΒΆ
This section is empty.
Variables ΒΆ
var ( LowerCaseLettersCharset = []rune("abcdefghijklmnopqrstuvwxyz") UpperCaseLettersCharset = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ") LettersCharset = append(LowerCaseLettersCharset, UpperCaseLettersCharset...) NumbersCharset = []rune("0123456789") AlphanumericCharset = append(LettersCharset, NumbersCharset...) SpecialCharset = []rune("!@#$%^&*()_+-=[]{}|;':\",./<>?") AllCharset = append(AlphanumericCharset, SpecialCharset...) )
Functions ΒΆ
func Assign ΒΆ
func Assign[K comparable, V any](maps ...map[K]V) map[K]V
Assign merges multiple maps from left to right. Play: https://go.dev/play/p/VhwfJOyxf5o
func Associate ΒΆ added in v1.26.0
func Associate[T any, K comparable, V any](collection []T, transform func(item T) (K, V)) map[K]V
Associate returns a map containing key-value pairs provided by transform function applied to elements of the given slice. If any of two pairs would have the same key the last one gets added to the map. The order of keys in returned map is not specified and is not guaranteed to be the same from the original array. Play: https://go.dev/play/p/WHa2CfMO3Lr
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 Async1 ΒΆ added in v1.17.0
func Async1[A any](f func() A) <-chan A
Async1 is an alias to Async.
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
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]
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. Play: https://go.dev/play/p/3ggJZ2ZKcMj
func AttemptWhile ΒΆ added in v1.36.0
AttemptWhile invokes a function N times until it returns valid output. Returning either the caught error or nil, and along with a bool value to identify whether it needs invoke function continuously. It will terminate the invoke immediately if second bool value is returned with falsy value. When first argument is less than `1`, the function runs until a successful response is returned.
func AttemptWhileWithDelay ΒΆ added in v1.36.0
func AttemptWhileWithDelay(maxIteration int, delay time.Duration, f func(int, time.Duration) (error, bool)) (int, time.Duration, error)
AttemptWhileWithDelay invokes a function N times until it returns valid output, with a pause between each call. Returning either the caught error or nil, and along with a bool value to identify whether it needs to invoke function continuously. It will terminate the invoke immediately if second bool value is returned with falsy value. 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(index int, duration 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. Play: https://go.dev/play/p/tVs6CygC7m1
func BatchWithTimeout
deprecated
added in
v1.31.0
func Buffer ΒΆ added in v1.35.0
func Buffer[T any](ch <-chan T, size int) (collection []T, length int, readTime time.Duration, ok bool)
Buffer creates a slice of n elements from a channel. Returns the slice and the slice length. @TODO: we should probably provide an helper that reuse the same buffer.
func BufferWithTimeout ΒΆ added in v1.35.0
func BufferWithTimeout[T any](ch <-chan T, size int, timeout time.Duration) (collection []T, length int, readTime time.Duration, ok bool)
BufferWithTimeout creates a slice of n elements from a channel, with timeout. Returns the slice and the slice length. @TODO: we should probably provide an helper that reuse the same buffer.
func ChannelDispatcher ΒΆ added in v1.28.0
func ChannelDispatcher[T any](stream <-chan T, count int, channelBufferCap int, strategy DispatchingStrategy[T]) []<-chan T
ChannelDispatcher distributes messages from input channels into N child channels. Close events are propagated to children. Underlying channels can have a fixed buffer capacity or be unbuffered when cap is 0.
func ChannelMerge
deprecated
added in
v1.33.0
func ChannelToSlice ΒΆ added in v1.32.0
func ChannelToSlice[T any](ch <-chan T) []T
ChannelToSlice returns a slice built from channels items. Blocks until channel closes.
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. Play: https://go.dev/play/p/EeKl0AuTehH
func ChunkString ΒΆ added in v1.27.0
ChunkString returns an array of strings split into groups the length of size. If array can't be split evenly, the final chunk will be the remaining elements. Play: https://go.dev/play/p/__FLTuJVz54
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. Play: https://go.dev/play/p/RU4lJNC2hlI
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. Play: https://go.dev/play/p/tXiy-iK6PAc
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. Play: https://go.dev/play/p/Y3FlK54yveC
func CountBy ΒΆ added in v1.12.0
CountBy counts the number of elements in the collection for which predicate is true. Play: https://go.dev/play/p/ByQbNYQQi4X
func CountValues ΒΆ added in v1.32.0
func CountValues[T comparable](collection []T) map[T]int
CountValues counts the number of each element in the collection. Play: https://go.dev/play/p/-p-PyLT4dfy
func CountValuesBy ΒΆ added in v1.32.0
func CountValuesBy[T any, U comparable](collection []T, mapper func(item T) U) map[U]int
CountValuesBy counts the number of each element return from mapper function. Is equivalent to chaining lo.Map and lo.CountValues. Play: https://go.dev/play/p/2U0dG1SnOmS
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 DispatchingStrategyFirst ΒΆ added in v1.28.0
DispatchingStrategyFirst distributes messages in the first non-full channel. If the capacity of the first channel is exceeded, the second channel will be selected and so on.
func DispatchingStrategyLeast ΒΆ added in v1.28.0
DispatchingStrategyLeast distributes messages in the emptiest channel.
func DispatchingStrategyMost ΒΆ added in v1.28.0
DispatchingStrategyMost distributes messages in the fullest channel. If the channel capacity is exceeded, the next channel will be selected and so on.
func DispatchingStrategyRandom ΒΆ added in v1.28.0
DispatchingStrategyRandom distributes messages in a random manner. If the channel capacity is exceeded, another random channel will be selected and so on.
func DispatchingStrategyRoundRobin ΒΆ added in v1.28.0
DispatchingStrategyRoundRobin distributes messages in a rotating sequential manner. If the channel capacity is exceeded, the next channel will be selected and so on.
func Drop ΒΆ added in v1.9.0
Drop drops n elements from the beginning of a slice or array. Play: https://go.dev/play/p/JswS7vXRJP2
func DropRight ΒΆ added in v1.9.0
DropRight drops n elements from the end of a slice or array. Play: https://go.dev/play/p/GG0nXkSJJa3
func DropRightWhile ΒΆ added in v1.9.0
DropRightWhile drops elements from the end of a slice or array while the predicate returns true. Play: https://go.dev/play/p/3-n71oEC0Hz
func DropWhile ΒΆ added in v1.9.0
DropWhile drops elements from the beginning of a slice or array while the predicate returns true. Play: https://go.dev/play/p/7gBPYw2IK16
func EmptyableToPtr ΒΆ added in v1.38.0
func EmptyableToPtr[T any](x T) *T
EmptyableToPtr returns a pointer copy of value if it's nonzero. Otherwise, returns nil pointer.
func ErrorsAs ΒΆ added in v1.29.0
ErrorsAs is a shortcut for errors.As(err, &&T). Play: https://go.dev/play/p/8wk5rH8UfrE
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 FanIn ΒΆ added in v1.34.0
FanIn collects messages from multiple input channels into a single buffered channel. Output messages has no priority. When all upstream channels reach EOF, downstream channel closes.
func FanOut ΒΆ added in v1.34.0
FanOut broadcasts all the upstream messages to multiple downstream channels. When upstream channel reach EOF, downstream channels close. If any downstream channels is full, broadcasting is paused.
func Fill ΒΆ
func Fill[T Clonable[T]](collection []T, initial T) []T
Fill fills elements of array with `initial` value. Play: https://go.dev/play/p/VwR34GzqEub
func Filter ΒΆ
Filter iterates over elements of collection, returning an array of all elements predicate returns truthy for. Play: https://go.dev/play/p/Apjg3WeSi7K
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 FindDuplicates ΒΆ added in v1.25.0
func FindDuplicates[T comparable](collection []T) []T
FindDuplicates returns a slice with the first occurrence of each duplicated elements of the collection. The order of result values is determined by the order they occur in the collection.
func FindDuplicatesBy ΒΆ added in v1.25.0
func FindDuplicatesBy[T any, U comparable](collection []T, iteratee func(item T) U) []T
FindDuplicatesBy returns a slice with the first occurrence of each duplicated elements of the collection. 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 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 FindKey ΒΆ added in v1.23.0
func FindKey[K comparable, V comparable](object map[K]V, value V) (K, bool)
FindKey returns the key of the first value matching.
func FindKeyBy ΒΆ added in v1.23.0
func FindKeyBy[K comparable, V any](object map[K]V, predicate func(key K, value V) bool) (K, bool)
FindKeyBy returns the key of the first element predicate returns truthy for.
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 FindUniques ΒΆ added in v1.25.0
func FindUniques[T comparable](collection []T) []T
FindUniques returns a slice with all the unique elements of the collection. The order of result values is determined by the order they occur in the collection.
func FindUniquesBy ΒΆ added in v1.25.0
func FindUniquesBy[T any, U comparable](collection []T, iteratee func(item T) U) []T
FindUniquesBy returns a slice with all the unique elements of the collection. 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 FlatMap ΒΆ added in v1.7.0
FlatMap manipulates a slice and transforms and flattens it to a slice of another type. The transform function can either return a slice or a `nil`, and in the `nil` case no value is added to the final slice. Play: https://go.dev/play/p/YSoYmQTA8-U
func Flatten ΒΆ
func Flatten[T any](collection [][]T) []T
Flatten returns an array a single level deep. Play: https://go.dev/play/p/rbp9ORaMpjw
func ForEach ΒΆ
ForEach iterates over elements of collection and invokes iteratee for each element. Play: https://go.dev/play/p/oofyiUPRf8t
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. Play: https://go.dev/play/p/oIr5KHFGCEN
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(). Play: https://go.dev/play/p/oIr5KHFGCEN
func FromPtr ΒΆ added in v1.22.0
func FromPtr[T any](x *T) T
FromPtr returns the pointer value or empty.
func FromPtrOr ΒΆ added in v1.26.0
func FromPtrOr[T any](x *T, fallback T) T
FromPtrOr returns the pointer value or the fallback value.
func GroupBy ΒΆ
func GroupBy[T any, U comparable](collection []T, iteratee func(item T) U) map[U][]T
GroupBy returns an object composed of keys generated from the results of running each element of collection through iteratee. Play: https://go.dev/play/p/XnQBd_v6brd
func If ΒΆ
If. Play: https://go.dev/play/p/WSw3ApMxhyW
func IfF ΒΆ added in v1.13.0
IfF. Play: https://go.dev/play/p/WSw3ApMxhyW
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 Interleave ΒΆ added in v1.32.0
func Interleave[T any](collections ...[]T) []T
Interleave round-robin alternating input slices and sequentially appending value at index into result Play: https://go.dev/play/p/DDhlwrShbwe
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. Play: https://go.dev/play/p/rFQ4rak6iA1
func IsEmpty ΒΆ added in v1.22.0
func IsEmpty[T comparable](v T) bool
IsEmpty returns true if argument is a zero value.
func IsNotEmpty ΒΆ added in v1.25.0
func IsNotEmpty[T comparable](v T) bool
IsNotEmpty returns true if argument is not a zero value.
func IsSorted ΒΆ added in v1.26.0
func IsSorted[T constraints.Ordered](collection []T) bool
IsSorted checks if a slice is sorted. Play: https://go.dev/play/p/mc3qR-t4mcx
func IsSortedByKey ΒΆ added in v1.26.0
func IsSortedByKey[T any, K constraints.Ordered](collection []T, iteratee func(item T) K) bool
IsSortedByKey checks if a slice is sorted by iteratee. Play: https://go.dev/play/p/wiG6XyBBu49
func KeyBy ΒΆ added in v1.10.1
func KeyBy[K comparable, V any](collection []V, iteratee func(item V) K) map[K]V
KeyBy transforms a slice or an array of structs to a map based on a pivot callback. Play: https://go.dev/play/p/mdaClUAT-zZ
func Keys ΒΆ
func Keys[K comparable, V any](in map[K]V) []K
Keys creates an array of the map keys. Play: https://go.dev/play/p/Uu11fHASqrU
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 Map ΒΆ
Map manipulates a slice and transforms it to a slice of another type. Play: https://go.dev/play/p/OkPcYAhBo0D
func MapEntries ΒΆ added in v1.32.0
func MapEntries[K1 comparable, V1 any, K2 comparable, V2 any](in map[K1]V1, iteratee func(key K1, value V1) (K2, V2)) map[K2]V2
MapEntries manipulates a map entries and transforms it to a map of another type. Play: https://go.dev/play/p/VuvNQzxKimT
func MapKeys ΒΆ added in v1.13.0
func MapKeys[K comparable, V any, R comparable](in map[K]V, iteratee func(value V, key K) R) map[R]V
MapKeys manipulates a map keys and transforms it to a map of another type. Play: https://go.dev/play/p/9_4WPIqOetJ
func MapToSlice ΒΆ added in v1.26.0
func MapToSlice[K comparable, V any, R any](in map[K]V, iteratee func(key K, value V) R) []R
MapToSlice transforms a map into a slice based on specific iteratee Play: https://go.dev/play/p/ZuiCZpDt6LD
func MapValues ΒΆ added in v1.7.0
func MapValues[K comparable, V any, R any](in map[K]V, iteratee func(value V, key K) R) map[K]R
MapValues manipulates a map values and transforms it to a map of another type. Play: https://go.dev/play/p/T_8xAfvcf0W
func Max ΒΆ
func Max[T constraints.Ordered](collection []T) T
Max searches the maximum value of a collection. Returns zero value when collection is empty.
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. Returns zero value when collection is empty.
func Min ΒΆ
func Min[T constraints.Ordered](collection []T) T
Min search the minimum value of a collection. Returns zero value when collection is empty.
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. Returns zero value when collection is empty.
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. Play: https://go.dev/play/p/TMoWrRp3DyC
func Must0 ΒΆ added in v1.12.0
func Must0(err any, messageArgs ...interface{})
Must0 has the same behavior as Must, but callback returns no variable. Play: https://go.dev/play/p/TMoWrRp3DyC
func Must1 ΒΆ added in v1.12.0
Must1 is an alias to Must Play: https://go.dev/play/p/TMoWrRp3DyC
func Must2 ΒΆ added in v1.12.0
Must2 has the same behavior as Must, but callback returns 2 variables. Play: https://go.dev/play/p/TMoWrRp3DyC
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 as Must, but callback returns 3 variables. Play: https://go.dev/play/p/TMoWrRp3DyC
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 as Must, but callback returns 4 variables. Play: https://go.dev/play/p/TMoWrRp3DyC
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 as Must, but callback returns 5 variables. Play: https://go.dev/play/p/TMoWrRp3DyC
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 as Must, but callback returns 6 variables. Play: https://go.dev/play/p/TMoWrRp3DyC
func NewDebounce ΒΆ added in v1.11.0
NewDebounce creates a debounced instance that delays invoking functions given until after wait milliseconds have elapsed. Play: https://go.dev/play/p/mz32VMK2nqe
func NewDebounceBy ΒΆ added in v1.38.0
func NewDebounceBy[T comparable](duration time.Duration, f ...func(key T, count int)) (func(key T), func(key T))
NewDebounceBy creates a debounced instance for each distinct key, that delays invoking functions given until after wait milliseconds have elapsed. Play: https://go.dev/play/p/d3Vpt6pxhY8
func None ΒΆ added in v1.18.0
func None[T comparable](collection []T, subset []T) 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 ΒΆ
func Nth[T any, N constraints.Integer](collection []T, nth N) (T, error)
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(key K, value V) bool) map[K]V
OmitBy returns same map type filtered by given predicate. Play: https://go.dev/play/p/EtBsR43bdsd
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. Play: https://go.dev/play/p/t1QjCrs-ysk
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. Play: https://go.dev/play/p/9UYZi-hrs8j
func Partial ΒΆ added in v1.22.0
func Partial[T1, T2, R any](f func(a T1, b T2) R, arg1 T1) func(T2) R
Partial returns new function that, when called, has its first argument set to the provided value.
func Partial1 ΒΆ added in v1.37.0
func Partial1[T1, T2, R any](f func(T1, T2) R, arg1 T1) func(T2) R
Partial1 returns new function that, when called, has its first argument set to the provided value.
func Partial2 ΒΆ added in v1.37.0
func Partial2[T1, T2, T3, R any](f func(T1, T2, T3) R, arg1 T1) func(T2, T3) R
Partial2 returns new function that, when called, has its first argument set to the provided value.
func Partial3 ΒΆ added in v1.37.0
func Partial3[T1, T2, T3, T4, R any](f func(T1, T2, T3, T4) R, arg1 T1) func(T2, T3, T4) R
Partial3 returns new function that, when called, has its first argument set to the provided value.
func Partial4 ΒΆ added in v1.37.0
func Partial4[T1, T2, T3, T4, T5, R any](f func(T1, T2, T3, T4, T5) R, arg1 T1) func(T2, T3, T4, T5) R
Partial4 returns new function that, when called, has its first argument set to the provided value.
func Partial5 ΒΆ added in v1.37.0
func Partial5[T1, T2, T3, T4, T5, T6, R any](f func(T1, T2, T3, T4, T5, T6) R, arg1 T1) func(T2, T3, T4, T5, T6) R
Partial5 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(item 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. Play: https://go.dev/play/p/NfQ_nGjkgXW
func PickBy ΒΆ added in v1.13.0
func PickBy[K comparable, V any](in map[K]V, predicate func(key K, value V) bool) map[K]V
PickBy returns same map type filtered by given predicate. Play: https://go.dev/play/p/kdg8GR_QMmf
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. Play: https://go.dev/play/p/R1imbuci9qU
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. Play: https://go.dev/play/p/1zdzSvbfsJc
func RandomString ΒΆ added in v1.35.0
RandomString return a random string. Play: https://go.dev/play/p/rRseOQVVum4
func Range ΒΆ added in v1.10.0
Range creates an array of numbers (positive and/or negative) with given length. Play: https://go.dev/play/p/0r6VimXAi9H
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. Play: https://go.dev/play/p/0r6VimXAi9H
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. Play: https://go.dev/play/p/0r6VimXAi9H
func Reduce ΒΆ
func Reduce[T any, R any](collection []T, accumulator func(agg R, item T, index int) R, initial R) R
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. Play: https://go.dev/play/p/R4UHXZNaaUG
func ReduceRight ΒΆ added in v1.26.0
func ReduceRight[T any, R any](collection []T, accumulator func(agg R, item T, index int) R, initial R) R
ReduceRight helper is like Reduce except that it iterates over elements of collection from right to left. Play: https://go.dev/play/p/Fq3W70l7wXF
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. Play: https://go.dev/play/p/YkLMODy1WEL
func Repeat ΒΆ added in v1.5.0
Repeat builds a slice with N copies of initial value. Play: https://go.dev/play/p/g3uHXbmc3b6
func RepeatBy ΒΆ added in v1.19.0
RepeatBy builds a slice with values returned by N calls of callback. Play: https://go.dev/play/p/ozZLCtX_hNU
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. Play: https://go.dev/play/p/XfPzmf9gql6
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. Play: https://go.dev/play/p/a9xZFUHfYcV
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. Play: https://go.dev/play/p/fhUMLvZ7vS6
func RuneLength ΒΆ added in v1.19.0
RuneLength is an alias to utf8.RuneCountInString which returns the number of runes in string. Play: https://go.dev/play/p/tuhgW_lWY8l
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. Play: https://go.dev/play/p/Qp73bnTDnc7
func Slice ΒΆ added in v1.22.0
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. Play: https://go.dev/play/p/8XWYhfMMA1h
func SliceToChannel ΒΆ added in v1.31.0
SliceToChannel returns a read-only channels of collection elements.
func SliceToMap ΒΆ added in v1.27.0
func SliceToMap[T any, K comparable, V any](collection []T, transform func(item T) (K, V)) map[K]V
SliceToMap returns a map containing key-value pairs provided by transform function applied to elements of the given slice. If any of two pairs would have the same key the last one gets added to the map. The order of keys in returned map is not specified and is not guaranteed to be the same from the original array. Alias of Associate(). Play: https://go.dev/play/p/WHa2CfMO3Lr
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. Play: https://go.dev/play/p/tOQu1GhFcog
func Substring ΒΆ added in v1.19.0
Substring return part of a string. Play: https://go.dev/play/p/TQlxQi82Lu1
func Sum ΒΆ added in v1.32.0
func Sum[T constraints.Float | constraints.Integer | constraints.Complex](collection []T) T
Sum sums the values in a collection. If collection is empty 0 is returned. Play: https://go.dev/play/p/upfeJVqs4Bt
func SumBy ΒΆ added in v1.20.0
func SumBy[T any, R constraints.Float | constraints.Integer | constraints.Complex](collection []T, iteratee func(item T) R) R
SumBy summarizes the values in a collection using the given return value from the iteration function. If collection is empty 0 is returned. Play: https://go.dev/play/p/Dz_a_7jN_ca
func Switch ΒΆ
func Switch[T comparable, R any](predicate T) *switchCase[T, R]
Switch is a pure functional switch/case/default statement. Play: https://go.dev/play/p/TGbKUMAeRUd
func Synchronize ΒΆ added in v1.20.0
Synchronize wraps the underlying callback in a mutex. It receives an optional mutex.
func Ternary ΒΆ
Ternary is a 1 line if/else statement. Play: https://go.dev/play/p/t-D7WBL44h2
func TernaryF ΒΆ added in v1.30.0
TernaryF is a 1 line if/else statement whose options are functions Play: https://go.dev/play/p/AO4VW20JoqM
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. Play: https://go.dev/play/p/vgQj3Glr6lT
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 as Try, but callback returns no variable. Play: https://go.dev/play/p/mTyyWUvn9u4
func Try1 ΒΆ added in v1.11.0
Try1 is an alias to Try. Play: https://go.dev/play/p/mTyyWUvn9u4
func Try2 ΒΆ added in v1.11.0
Try2 has the same behavior as Try, but callback returns 2 variables. Play: https://go.dev/play/p/mTyyWUvn9u4
func Try3 ΒΆ added in v1.11.0
Try3 has the same behavior as Try, but callback returns 3 variables. Play: https://go.dev/play/p/mTyyWUvn9u4
func Try4 ΒΆ added in v1.11.0
Try4 has the same behavior as Try, but callback returns 4 variables. Play: https://go.dev/play/p/mTyyWUvn9u4
func Try5 ΒΆ added in v1.11.0
Try5 has the same behavior as Try, but callback returns 5 variables. Play: https://go.dev/play/p/mTyyWUvn9u4
func Try6 ΒΆ added in v1.11.0
Try6 has the same behavior as Try, but callback returns 6 variables. Play: https://go.dev/play/p/mTyyWUvn9u4
func TryCatch ΒΆ added in v1.11.0
func TryCatch(callback func() error, catch func())
TryCatch has the same behavior as Try, but calls the catch function in case of error. Play: https://go.dev/play/p/PnOON-EqBiU
func TryCatchWithErrorValue ΒΆ added in v1.11.0
TryCatchWithErrorValue has the same behavior as TryWithErrorValue, but calls the catch function in case of error. Play: https://go.dev/play/p/8Pc9gwX_GZO
func TryOr ΒΆ added in v1.29.0
TryOr has the same behavior as Must, but returns a default value in case of error. Play: https://go.dev/play/p/B4F7Wg2Zh9X
func TryOr1 ΒΆ added in v1.29.0
TryOr1 has the same behavior as Must, but returns a default value in case of error. Play: https://go.dev/play/p/B4F7Wg2Zh9X
func TryOr2 ΒΆ added in v1.29.0
TryOr2 has the same behavior as Must, but returns a default value in case of error. Play: https://go.dev/play/p/B4F7Wg2Zh9X
func TryOr3 ΒΆ added in v1.29.0
func TryOr3[A any, B any, C any](callback func() (A, B, C, error), fallbackA A, fallbackB B, fallbackC C) (A, B, C, bool)
TryOr3 has the same behavior as Must, but returns a default value in case of error. Play: https://go.dev/play/p/B4F7Wg2Zh9X
func TryOr4 ΒΆ added in v1.29.0
func TryOr4[A any, B any, C any, D any](callback func() (A, B, C, D, error), fallbackA A, fallbackB B, fallbackC C, fallbackD D) (A, B, C, D, bool)
TryOr4 has the same behavior as Must, but returns a default value in case of error. Play: https://go.dev/play/p/B4F7Wg2Zh9X
func TryOr5 ΒΆ added in v1.29.0
func TryOr5[A any, B any, C any, D any, E any](callback func() (A, B, C, D, E, error), fallbackA A, fallbackB B, fallbackC C, fallbackD D, fallbackE E) (A, B, C, D, E, bool)
TryOr5 has the same behavior as Must, but returns a default value in case of error. Play: https://go.dev/play/p/B4F7Wg2Zh9X
func TryOr6 ΒΆ added in v1.29.0
func TryOr6[A any, B any, C any, D any, E any, F any](callback func() (A, B, C, D, E, F, error), fallbackA A, fallbackB B, fallbackC C, fallbackD D, fallbackE E, fallbackF F) (A, B, C, D, E, F, bool)
TryOr6 has the same behavior as Must, but returns a default value in case of error. Play: https://go.dev/play/p/B4F7Wg2Zh9X
func TryWithErrorValue ΒΆ added in v1.11.0
TryWithErrorValue has the same behavior as Try, but also returns value passed to panic. Play: https://go.dev/play/p/Kc7afQIT2Fs
func Union ΒΆ added in v1.8.0
func Union[T comparable](lists ...[]T) []T
Union returns all distinct elements from given 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. Play: https://go.dev/play/p/DTzbeXZ6iEN
func UniqBy ΒΆ
func UniqBy[T any, U comparable](collection []T, iteratee func(item 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. Play: https://go.dev/play/p/g42Z3QSb53u
func Unpack2 ΒΆ added in v1.17.0
Unpack2 returns values contained in tuple. Play: https://go.dev/play/p/xVP_k0kJ96W
func Unpack3 ΒΆ added in v1.17.0
Unpack3 returns values contained in tuple. Play: https://go.dev/play/p/xVP_k0kJ96W
func Unpack4 ΒΆ added in v1.17.0
Unpack4 returns values contained in tuple. Play: https://go.dev/play/p/xVP_k0kJ96W
func Unpack5 ΒΆ added in v1.17.0
Unpack5 returns values contained in tuple. Play: https://go.dev/play/p/xVP_k0kJ96W
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. Play: https://go.dev/play/p/xVP_k0kJ96W
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. Play: https://go.dev/play/p/xVP_k0kJ96W
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. Play: https://go.dev/play/p/xVP_k0kJ96W
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. Play: https://go.dev/play/p/xVP_k0kJ96W
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. Play: https://go.dev/play/p/ciHugugvaAW
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. Play: https://go.dev/play/p/ciHugugvaAW
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. Play: https://go.dev/play/p/ciHugugvaAW
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. Play: https://go.dev/play/p/ciHugugvaAW
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. Play: https://go.dev/play/p/ciHugugvaAW
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. Play: https://go.dev/play/p/ciHugugvaAW
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. Play: https://go.dev/play/p/ciHugugvaAW
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. Play: https://go.dev/play/p/ciHugugvaAW
func Validate ΒΆ added in v1.30.0
Validate is a helper that creates an error when a condition is not met. Play: https://go.dev/play/p/vPyh51XpCBt
func ValueOr ΒΆ added in v1.38.0
func ValueOr[K comparable, V any](in map[K]V, key K, fallback V) V
ValueOr returns the value of the given key or the fallback value if the key is not present. Play: https://go.dev/play/p/bAq9mHErB4V
func Values ΒΆ
func Values[K comparable, V any](in map[K]V) []V
Values creates an array of the map values. Play: https://go.dev/play/p/nnRTQkzQfF6
func Without ΒΆ added in v1.24.0
func Without[T comparable](collection []T, exclude ...T) []T
Without returns slice excluding all given values.
func WithoutEmpty ΒΆ added in v1.24.0
func WithoutEmpty[T comparable](collection []T) []T
WithoutEmpty returns slice excluding empty values.
Types ΒΆ
type Clonable ΒΆ
type Clonable[T any] interface { Clone() T }
Clonable defines a constraint of types having Clone() T method.
type DispatchingStrategy ΒΆ added in v1.28.0
func DispatchingStrategyWeightedRandom ΒΆ added in v1.28.0
func DispatchingStrategyWeightedRandom[T any](weights []int) DispatchingStrategy[T]
DispatchingStrategyWeightedRandom distributes messages in a weighted manner. If the channel capacity is exceeded, another random channel will be selected and so on.
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. Play:
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(). Play: https://go.dev/play/p/3Dhgx46gawJ
type Transaction ΒΆ added in v1.37.0
type Transaction[T any] struct { // contains filtered or unexported fields }
Transaction implements a Saga pattern
func NewTransaction ΒΆ added in v1.37.0
func NewTransaction[T any]() *Transaction[T]
NewTransaction instanciate a new transaction.
func (*Transaction[T]) Process ΒΆ added in v1.37.0
func (t *Transaction[T]) Process(state T) (T, error)
Process runs the Transaction steps and rollbacks in case of errors.
func (*Transaction[T]) Then ΒΆ added in v1.37.0
func (t *Transaction[T]) Then(exec func(T) (T, error), onRollback func(T) T) *Transaction[T]
Then adds a step to the chain of callbacks. It returns the same Transaction.
type Tuple2 ΒΆ added in v1.4.0
Tuple2 is a group of 2 elements (pair).
func T2 ΒΆ added in v1.13.0
T2 creates a tuple from a list of values. Play: https://go.dev/play/p/IllL3ZO4BQm
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. Play: https://go.dev/play/p/jujaA6GaJTp
type Tuple3 ΒΆ added in v1.4.0
Tuple3 is a group of 3 elements.
func T3 ΒΆ added in v1.13.0
T3 creates a tuple from a list of values. Play: https://go.dev/play/p/IllL3ZO4BQm
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. Play: https://go.dev/play/p/jujaA6GaJTp
type Tuple4 ΒΆ added in v1.4.0
Tuple4 is a group of 4 elements.
func T4 ΒΆ added in v1.13.0
T4 creates a tuple from a list of values. Play: https://go.dev/play/p/IllL3ZO4BQm
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. Play: https://go.dev/play/p/jujaA6GaJTp
type Tuple5 ΒΆ added in v1.4.0
Tuple5 is a group of 5 elements.
func T5 ΒΆ added in v1.13.0
T5 creates a tuple from a list of values. Play: https://go.dev/play/p/IllL3ZO4BQm
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. Play: https://go.dev/play/p/jujaA6GaJTp
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. Play: https://go.dev/play/p/IllL3ZO4BQm
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. Play: https://go.dev/play/p/jujaA6GaJTp
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. Play: https://go.dev/play/p/IllL3ZO4BQm
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. Play: https://go.dev/play/p/jujaA6GaJTp
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. Play: https://go.dev/play/p/IllL3ZO4BQm
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. Play: https://go.dev/play/p/jujaA6GaJTp
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]
T9 creates a tuple from a list of values. Play: https://go.dev/play/p/IllL3ZO4BQm
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. Play: https://go.dev/play/p/jujaA6GaJTp