Documentation ¶
Index ¶
- Variables
- func After(n int, function func()) func()
- func Associate[T any, K comparable, V any](collection []T, transform func(t T, index int) (K, V)) map[K]V
- func Buffer[T any](ch <-chan T, size int) (collection []T, length int, readTime time.Duration, closed bool)
- func BufferWithTimeout[T any](ch <-chan T, size int, timeout time.Duration) (collection []T, length int, readTime time.Duration, closed bool)
- func CamelCase(raw string) string
- func Capitalize(raw string) string
- func ChannelDispatcher[T any](stream <-chan T, count int, channelBufferCap int, ...) []<-chan T
- func ChannelToSlice[T any](ch <-chan T) []T
- func Chunk[T any](collection []T, size int) [][]T
- func ChunkString[T ~string](str T, size int) []T
- func CollectionToSet[T comparable](collection []T) map[T]struct{}
- func Contains[T comparable](collection []T, element T) bool
- func ContainsBy[T comparable](collection []T, predicate func(item T) bool) bool
- func Count[T comparable](collection []T, value T) int
- func CountBy[T any, K comparable](collection []T, iteratee func(item T, index int) K) map[K]int
- func DispatchingStrategyFirst[T any](msg T, index uint64, channels []<-chan T) int
- func DispatchingStrategyLeast[T any](msg T, index uint64, channels []<-chan T) int
- func DispatchingStrategyMost[T any](msg T, index uint64, channels []<-chan T) int
- func DispatchingStrategyRandom[T any](msg T, index uint64, channels []<-chan T) int
- func DispatchingStrategyRoundRobin[T any](msg T, index uint64, channels []<-chan T) int
- 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(item T, index int) bool) []T
- func DropWhile[T any](collection []T, predicate func(item T, index int) bool) []T
- func Every[T comparable](collection []T, subset []T) bool
- func EveryBy[T comparable](collection []T, predicate func(item T) bool) bool
- func FanIn[T any](channelBufferCap int, upstreams ...<-chan T) <-chan T
- func FanOut[T any](count, channelBufferCap int, upstream <-chan T) []<-chan T
- func Fill[T any](collection []T, initial T) []T
- func FillWithClone[T Cloneable[T]](collection []T, initial T) []T
- func Filter[T any](collection []T, predicate func(item T, index int) bool) []T
- func FilterMap[T any, R any](collection []T, callback func(item T, index int) (R, bool)) []R
- func FindBy[T any](collection []T, comparison func(a, b T) bool) T
- func FlatMap[T any, R any](collection []T, iteratee func(item T, index int) []R) []R
- func Flatten[T any](collection [][]T) []T
- func ForEach[T any](collection []T, iteratee func(item T, index int))
- func ForEachRight[T any](collection []T, iteratee func(item T, index int))
- func FromAnySlice[T any](collection []any) ([]T, bool)
- func FromEntries[K comparable, V any](entries []Entry[K, V]) map[K]V
- func FromPtr[T any](x *T) T
- func FromPtrWithFallback[T any](x *T, fallback T) T
- func FromSlicePtr[T any](collection []*T) []T
- func FromSlicePtrWithFallback[T any](collection []*T, fallback T) []T
- func Generator[T any](bufferSize int, generator func(yield func(T))) <-chan T
- func GroupBy[T any, U comparable](collection []T, iteratee func(item T, index int) U) map[U][]T
- func Head[T any](collection []T) (T, bool)
- func If[T any](condition bool, t T) *ifElse[T]
- func IfF[T any](condition bool, predicate func() T) *ifElse[T]
- func Initial[T any](collection []T) []T
- func Interleave[T any](collections ...[]T) []T
- func Intersect[T comparable](list1 []T, list2 []T) []T
- func Invert[K comparable, V comparable](in map[K]V) map[V]K
- func IsNotZero[T comparable](x T) bool
- func IsZero[T comparable](x T) bool
- func Join[T any](collection []T, separator string) string
- func KeyBy[K comparable, V any](collection []V, iteratee func(v V, index int) K) map[K]V
- func Keys[K comparable, V any](in map[K]V) []K
- func Last[T any](collection []T) (T, bool)
- func Map[T any, R any](collection []T, iteratee func(item T, index int) R) []R
- func MapEntries[K comparable, V any](in map[K]V, iteratee func(k K, v V) (K, V)) map[K]V
- func MapKeys[K comparable, V any](in map[K]V, iteratee func(k K, v V) K) map[K]V
- func MapOverMap[K comparable, V any](in map[K]V, iteratee func(k K, v V))
- func MapToSlice[K comparable, V any, R any](in map[K]V, iteratee func(k K, v V) R) []R
- func MapValues[K comparable, V any](in map[K]V, iteratee func(k K, v V) V) map[K]V
- func Max[T constraints.Ordered](elements ...T) T
- func Memoize[T any](function func(key string) T) func(key string) T
- func Merge[K comparable, V any](ins ...map[K]V) map[K]V
- func Min[T constraints.Ordered](elements ...T) T
- func NewDebounce(function func(), delay time.Duration) (call, flush, cancel func())
- func None[T comparable](collection []T, subset []T) bool
- func NoneBy[T comparable](collection []T, predicate func(item T) bool) bool
- func Nth[T any](collection []T, n int) (T, error)
- func OmitBy[K comparable, V any](in map[K]V, predicate func(key K, value 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 PanicIf(err error)
- func PartitionBy[T any, P comparable](collection []T, iteratee func(item T, index int) P) [][]T
- func PickBy[K comparable, V any](in map[K]V, predicate func(key K, value 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 RandomString(size int, charset []rune) string
- func Range[T constraints.Integer](elementNum int) []T
- func RangeFrom[T constraints.Integer | constraints.Float](from T, elementNum int) []T
- func RangeWithStep[T constraints.Integer | constraints.Float](from, step T, elementNum int) []T
- func Reduce[T any, R any](collection []T, accumulator func(agg R, item T, index int) R, initial R) R
- func ReduceRight[T any, R any](collection []T, accumulator func(agg R, item T, index int) R, initial R) R
- func Reject[T any](collection []T, predicate func(item T, index int) bool) []T
- func Remove[T comparable](collection []T, excludedValues ...T) []T
- func RemoveBy[T any](collection []T, predicate func(item T, index int) bool) []T
- func Repeat[T any](count int, initial T) []T
- func RepeatBy[T any](count int, predicate func(index int) T) []T
- func RepeatString(raw string, n int) string
- func RepeatWithClone[T Cloneable[T]](count int, initial T) []T
- func Reverse[T any](collection []T) []T
- func RuneLength(str string) int
- func SafelyRun(function func()) (err error)
- func Sample[T any](collection []T) (T, bool)
- func SampleSize[T any](collection []T, n int) []T
- func Shuffle[T any](collection []T) []T
- func Slice[T any](collection []T, start, end int) []T
- func SliceToChannel[T any](collection []T, bufferSize int) <-chan T
- func SliceWithCopy[T any](collection []T, start, end int) []T
- func SnakeCase(raw string) string
- func Some[T comparable](collection []T, subset []T) bool
- func SomeBy[T comparable](collection []T, predicate func(item T) bool) bool
- func SubString[T ~string](str T, offset int, size uint) T
- func Subtract[T comparable](list1 []T, list2 []T) []T
- func Sum[T constraints.Integer | constraints.Float | constraints.Complex](collection []T) T
- func SumBy[T any, R constraints.Integer | constraints.Float | constraints.Complex](collection []T, iteratee func(t T, index int) R) R
- func Switch[T any](predicate T) *switchCase[T]
- func Tail[T any](collection []T) []T
- func Take[T any](collection []T, n int) []T
- func TakeRight[T any](collection []T, n int) []T
- func TakeRightWhile[T any](collection []T, predicate func(item T, index int) bool) []T
- func TakeWhile[T any](collection []T, predicate func(item T, index int) bool) []T
- func Ternary[T any](condition bool, ifOutput, elseOutput T) T
- func TernaryF[T any](condition bool, ifFunc, elseFunc func() T) T
- func Times[T any](count int, iteratee func(index 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 Union[T comparable](lists ...[]T) []T
- func Uniq[T comparable](collection []T) []T
- func UniqBy[T any, U comparable](collection []T, iteratee func(item T, index int) U) []T
- func Unpack10[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](t10 Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)
- func Unpack11[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](t11 Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)
- func Unpack12[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](t12 Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)
- func Unpack13[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](t13 Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)
- func Unpack14[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](t14 Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)
- func Unpack15[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](t15 Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]) (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
- func Unpack16[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](...) (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16)
- func Unpack17[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](...) (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17)
- func Unpack2[T1 any, T2 any](t2 Tuple2[T1, T2]) (T1, T2)
- func Unpack3[T1 any, T2 any, T3 any](t3 Tuple3[T1, T2, T3]) (T1, T2, T3)
- func Unpack4[T1 any, T2 any, T3 any, T4 any](t4 Tuple4[T1, T2, T3, T4]) (T1, T2, T3, T4)
- func Unpack5[T1 any, T2 any, T3 any, T4 any, T5 any](t5 Tuple5[T1, T2, T3, T4, T5]) (T1, T2, T3, T4, T5)
- func Unpack6[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any](t6 Tuple6[T1, T2, T3, T4, T5, T6]) (T1, T2, T3, T4, T5, T6)
- func Unpack7[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any](t7 Tuple7[T1, T2, T3, T4, T5, T6, T7]) (T1, T2, T3, T4, T5, T6, T7)
- func Unpack8[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any](t8 Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]) (T1, T2, T3, T4, T5, T6, T7, T8)
- func Unpack9[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any](t9 Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) (T1, T2, T3, T4, T5, T6, T7, T8, T9)
- func Unzip10[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](collection []Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10)
- func Unzip11[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](collection []Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11)
- func Unzip12[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](collection []Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12)
- func Unzip13[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](collection []Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12, ...)
- func Unzip14[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](...) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12, ...)
- func Unzip15[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](...) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12, ...)
- func Unzip16[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](...) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12, ...)
- func Unzip17[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](...) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12, ...)
- func Unzip2[T1 any, T2 any](collection []Tuple2[T1, T2]) ([]T1, []T2)
- func Unzip3[T1 any, T2 any, T3 any](collection []Tuple3[T1, T2, T3]) ([]T1, []T2, []T3)
- func Unzip4[T1 any, T2 any, T3 any, T4 any](collection []Tuple4[T1, T2, T3, T4]) ([]T1, []T2, []T3, []T4)
- func Unzip5[T1 any, T2 any, T3 any, T4 any, T5 any](collection []Tuple5[T1, T2, T3, T4, T5]) ([]T1, []T2, []T3, []T4, []T5)
- func Unzip6[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any](collection []Tuple6[T1, T2, T3, T4, T5, T6]) ([]T1, []T2, []T3, []T4, []T5, []T6)
- func Unzip7[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any](collection []Tuple7[T1, T2, T3, T4, T5, T6, T7]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7)
- func Unzip8[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any](collection []Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8)
- func Unzip9[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any](collection []Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9)
- func ValueOr[K comparable, V any](in map[K]V, key K, fallback V) V
- func Values[K comparable, V any](in map[K]V) []V
- func Words(raw string) []string
- func Zero[T any]() T
- type Cloneable
- type DispatchingStrategy
- type Entry
- type Tuple10
- func Pack10[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](a T1, b T2, c T3, d T4, e T5, f T6, g T7, h T8, i T9, j T10) Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]
- func Zip10[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, ...) []Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]
- type Tuple11
- func Pack11[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](a T1, b T2, c T3, d T4, e T5, f T6, g T7, h T8, i T9, j T10, k T11) Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]
- func Zip11[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, ...) []Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]
- type Tuple12
- func Pack12[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](a T1, b T2, c T3, d T4, e T5, f T6, g T7, h T8, i T9, j T10, k T11, l T12) Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]
- func Zip12[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, ...) []Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]
- type Tuple13
- func Pack13[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](a T1, b T2, c T3, d T4, e T5, f T6, g T7, h T8, i T9, j T10, k T11, l T12, ...) Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]
- func Zip13[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, ...) []Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]
- type Tuple14
- func Pack14[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](a T1, b T2, c T3, d T4, e T5, f T6, g T7, h T8, i T9, j T10, k T11, l T12, ...) Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]
- func Zip14[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, ...) []Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]
- type Tuple15
- func Pack15[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](a T1, b T2, c T3, d T4, e T5, f T6, g T7, h T8, i T9, j T10, k T11, l T12, ...) Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]
- func Zip15[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, ...) []Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]
- type Tuple16
- func Pack16[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](a T1, b T2, c T3, d T4, e T5, f T6, g T7, h T8, i T9, j T10, k T11, l T12, ...) Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]
- func Zip16[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, ...) ...
- type Tuple17
- func Pack17[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](a T1, b T2, c T3, d T4, e T5, f T6, g T7, h T8, i T9, j T10, k T11, l T12, ...) ...
- func Zip17[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, ...](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, ...) ...
- type Tuple2
- type Tuple3
- type Tuple4
- type Tuple5
- type Tuple6
- type Tuple7
- func Pack7[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any](a T1, b T2, c T3, d T4, e T5, f T6, g T7) Tuple7[T1, T2, T3, T4, T5, T6, T7]
- func Zip7[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, ...) []Tuple7[T1, T2, T3, T4, T5, T6, T7]
- type Tuple8
- func Pack8[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any](a T1, b T2, c T3, d T4, e T5, f T6, g T7, h T8) Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]
- func Zip8[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, ...) []Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]
- type Tuple9
- func Pack9[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any](a T1, b T2, c T3, d T4, e T5, f T6, g T7, h T8, i T9) Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]
- func Zip9[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, ...) []Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]
Examples ¶
- After
- Associate
- CamelCase
- Capitalize
- Chunk
- ChunkString
- Drop
- DropRight
- DropRightWhile
- DropWhile
- Fill
- FillWithClone
- Filter
- FilterMap
- FlatMap
- Flatten
- ForEach
- ForEachRight
- FromAnySlice
- FromEntries
- FromPtr
- FromPtrWithFallback
- FromSlicePtr
- FromSlicePtrWithFallback
- GroupBy
- Head
- If
- IfF
- Initial
- Interleave
- Invert
- IsNotZero
- IsZero
- Join
- KeyBy
- Keys
- Last
- Map
- MapEntries
- MapKeys
- MapOverMap
- MapToSlice
- MapValues
- Max
- Merge
- Min
- NewDebounce
- Nth
- OmitBy
- OmitByKeys
- OmitByValues
- Pack10
- Pack11
- Pack2
- Pack3
- Pack4
- Pack5
- Pack6
- Pack7
- Pack8
- Pack9
- PanicIf
- PartitionBy
- PickBy
- PickByKeys
- PickByValues
- RandomString
- Range
- RangeFrom
- RangeWithStep
- Reduce
- ReduceRight
- Reject
- Remove
- RemoveBy
- Repeat
- RepeatBy
- RepeatString
- RepeatWithClone
- Reverse
- RuneLength
- SafelyRun
- SampleSize
- Shuffle
- Slice
- SliceWithCopy
- SnakeCase
- SubString
- Sum
- SumBy
- Switch
- Tail
- Take
- TakeRight
- TakeRightWhile
- TakeWhile
- Ternary
- TernaryF
- Times
- ToAnySlice
- ToEntries
- ToPtr
- ToSlicePtr
- Uniq
- UniqBy
- Unpack10
- Unpack11
- Unpack2
- Unpack3
- Unpack4
- Unpack5
- Unpack6
- Unpack7
- Unpack8
- Unpack9
- Unzip10
- Unzip11
- Unzip2
- Unzip3
- Unzip4
- Unzip5
- Unzip6
- Unzip7
- Unzip8
- Unzip9
- ValueOr
- Values
- Words
- Zero
- Zip10
- Zip11
- Zip2
- Zip3
- Zip4
- Zip5
- Zip6
- Zip7
- Zip8
- Zip9
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 After ¶
func After(n int, function func()) func()
After creates a function that invokes input `function` once it's called n or more times.
Example ¶
result := After(3, func() { fmt.Println("info") }) result() result() result() result()
Output: info info
func Associate ¶
func Associate[T any, K comparable, V any](collection []T, transform func(t T, index int) (K, V)) map[K]V
Associate transforms a slice to a map whose key-value pairs are generated by transform function.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := Associate(list, func(item int64, index int) (string, string) { return fmt.Sprintf("key-%d", item), fmt.Sprintf("value-%d", index) }) fmt.Printf("%+v", result)
Output: map[key-1:value-0 key-2:value-1 key-3:value-2 key-4:value-3 key-5:value-4]
func Buffer ¶
func Buffer[T any](ch <-chan T, size int) (collection []T, length int, readTime time.Duration, closed bool)
Buffer creates a slice of n elements from a channel. Returns the slice and slice length.
func BufferWithTimeout ¶
func BufferWithTimeout[T any](ch <-chan T, size int, timeout time.Duration) (collection []T, length int, readTime time.Duration, closed bool)
BufferWithTimeout
func CamelCase ¶
CamelCase returns camel-case version of input string.
Example ¶
result := CamelCase("hello, world!") fmt.Println(result)
Output: helloWorld
func Capitalize ¶
Capitalize converts the first character of string to upper case, and the remaining to lower case.
Example ¶
result := Capitalize("hello, world!") fmt.Println(result)
Output: Hello, world!
func ChannelDispatcher ¶
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 ChannelToSlice ¶
func ChannelToSlice[T any](ch <-chan T) []T
ChannelToSlice returns a slice built from channel items. Blocks until channel closes.
func Chunk ¶
Chunk returns an array of elements split into groups the length of size. If collection can't be split evenly, the final chunk will be the remaining elements.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := Chunk(list, 2) fmt.Printf("%+v", result)
Output: [[1 2] [3 4] [5]]
func ChunkString ¶
ChunkString returns chunks whose lengths are len(size), and from str.
Example ¶
result := ChunkString("abcde", 2) fmt.Println(result)
Output: [ab cd e]
func CollectionToSet ¶
func CollectionToSet[T comparable](collection []T) map[T]struct{}
func Contains ¶
func Contains[T comparable](collection []T, element T) bool
Contains returns true if an element present in a collection.
func ContainsBy ¶
func ContainsBy[T comparable](collection []T, predicate func(item T) bool) bool
ContainsBy returns true if predicate function return true.
func Count ¶
func Count[T comparable](collection []T, value T) int
Count returns the number of times of the value.
func CountBy ¶
func CountBy[T any, K comparable](collection []T, iteratee func(item T, index int) K) map[K]int
CountBy returns a map composed of keys generated from iteratee. The corresponding value of each key is the number of times the key was returned by iteratee.
func DispatchingStrategyFirst ¶
DispatchingStrategyFirst distributes messages in a first-non-full manner. If the channel capacity is exceeded, the second channel will be selected and so on.
func DispatchingStrategyLeast ¶
DispatchingStrategyLeast distributes messages in the emptiest channel.
func DispatchingStrategyMost ¶
DispatchingStrategyMost distributes messages in the fullest channel. If the channel capacity is exceeded, the next channel will be selected and so on.
func DispatchingStrategyRandom ¶
DispatchingStrategyRandom distributes messages in a random manner. If the channel capacity is exceeded, another random channel will be selected and so on.
func DispatchingStrategyRoundRobin ¶
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 ¶
Drop returns a slice with n elements dropped from the beginning of the collection.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := Drop(list, 2) fmt.Printf("%+v", result)
Output: [3 4 5]
func DropRight ¶
DropRight returns a slice with n elements dropped from the end of the collection.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := DropRight(list, 2) fmt.Printf("%+v", result)
Output: [1 2 3]
func DropRightWhile ¶
DropRightWhile returns a slice excluding elements dropped from the end. Elements are dropped until the predicate function returns falsey.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := DropRightWhile(list, func(item int64, index int) bool { return item > 3 }) fmt.Printf("%+v", result)
Output: [1 2 3]
func DropWhile ¶
DropWhile returns a slice excluding elements dropped from the beginning. Elements are dropped until the predicate function returns falsey.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := DropWhile(list, func(item int64, index int) bool { return item < 3 }) fmt.Printf("%+v", result)
Output: [3 4 5]
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 ¶
func EveryBy[T comparable](collection []T, predicate func(item T) bool) bool
EveryBy returns true if predicate function returns true for all elements in the collection or if the collection is empty.
func FanIn ¶
FanIn collects items from multiple channels into a single buffered channel. Output messages has no priority. When all upstream channels reach EOF, downstream channel closes.
func FanOut ¶
FanOut broadcasts all upstream messages to multiple downstream channels. When upstream channel EOF, downstream channels close. If any downstream channel is full, broadcasting is paused.
func Fill ¶
func Fill[T any](collection []T, initial T) []T
Fill fills the collection with initial value.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := Fill(list, 0) fmt.Printf("%+v", result)
Output: [0 0 0 0 0]
func FillWithClone ¶
func FillWithClone[T Cloneable[T]](collection []T, initial T) []T
FillWithClone fills the collection with cloned initial value.
Example ¶
list := []cloneableInt64{1, 2, 3, 4, 5} result := FillWithClone[cloneableInt64](list, cloneableInt64(0)) fmt.Printf("%+v", result)
Output: [0 0 0 0 0]
func Filter ¶
Filter iterates over elements of collection, returns an array of all elements that predicate function returns truthy for.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := Filter(list, func(item int64, index int) bool { return item%2 == 0 }) fmt.Printf("%+v", result)
Output: [2 4]
func FilterMap ¶
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.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := FilterMap(list, func(item int64, index int) (string, bool) { return strconv.FormatInt(item, 10), item%2 == 0 }) fmt.Printf("%+v", result)
Output: [2 4]
func FindBy ¶
FindBy returns minimum element in collection by comparison function. If there are multi minimum values, MinBy returns the first. If collection is empty, MinBy returns zero value of T. todo(wangli) Change name and description.
func FlatMap ¶
FlatMap manipulates a slice and transforms and flattens it to a slice of another type. The transform function either return a slice or a `nil`.
Example ¶
list := []int64{1, 23} result := FlatMap(list, func(item int64, index int) []string { return []string{ strconv.FormatInt(item, 10), strconv.FormatInt(item, 26), } }) fmt.Printf("%+v", result)
Output: [1 1 23 n]
func Flatten ¶
func Flatten[T any](collection [][]T) []T
Flatten returns an array of single level deep.
Example ¶
list := [][]int64{{1, 2}, {3, 4}, {5}} result := Flatten(list) fmt.Printf("%+v", result)
Output: [1 2 3 4 5]
func ForEach ¶
ForEach iterates over collection and invokes iteratee function for each element.
Example ¶
list := []int64{1, 2, 3, 4, 5} ForEach(list, func(item int64, index int) { fmt.Printf("%d:%d,", index, item) })
Output: 0:1,1:2,2:3,3:4,4:5,
func ForEachRight ¶
ForEachRight iterates over collection from the end and invokes iteratee function for each element.
Example ¶
list := []int64{1, 2, 3, 4, 5} ForEachRight(list, func(item int64, index int) { fmt.Printf("%d:%d,", index, item) })
Output: 4:5,3:4,2:3,1:2,0:1,
func FromAnySlice ¶
FromAnySlice returns a slice of elements whose types are T, from collection.
Example ¶
collection := []any{1, 2, "3", 4, 5} result, ok := FromAnySlice[int](collection) fmt.Println(result, ok)
Output: [1 2 0 4 5] false
func FromEntries ¶
func FromEntries[K comparable, V any](entries []Entry[K, V]) map[K]V
FromEntries returns a map build by entries.
Example ¶
es := []Entry[string, int]{ {"wang", 1}, {"zhao", 3}, } result := FromEntries(es) fmt.Printf("%+v", sprintSortedMapByKey(result))
Output: map[wang:1 zhao:3]
func FromPtr ¶
func FromPtr[T any](x *T) T
FromPtr returns the pointer value, or zero if pointer is nil.
Example ¶
x := 1 y := &x result := FromPtr(y) fmt.Println(result)
Output: 1
func FromPtrWithFallback ¶
func FromPtrWithFallback[T any](x *T, fallback T) T
FromPtrWithFallback returns the pointer value, or fallback if pointer is nil.
Example ¶
var x *int = nil result := FromPtrWithFallback(x, 1) fmt.Println(result)
Output: 1
func FromSlicePtr ¶
func FromSlicePtr[T any](collection []*T) []T
FromSlicePtr returns a slice of elements that are values of collection.
Example ¶
collection := []*int{ToPtr(1), ToPtr(2), ToPtr(3), ToPtr(4), ToPtr(5)} result := FromSlicePtr(collection) fmt.Println(result)
Output: [1 2 3 4 5]
func FromSlicePtrWithFallback ¶
func FromSlicePtrWithFallback[T any](collection []*T, fallback T) []T
FromSlicePtrWithFallback returns a slice of elements that are values with fallback of collection.
Example ¶
var nilValue *int = nil collection := []*int{ToPtr(1), ToPtr(2), nilValue, ToPtr(4), ToPtr(5)} result := FromSlicePtrWithFallback(collection, 7) fmt.Println(result)
Output: [1 2 7 4 5]
func Generator ¶
Generator implements the generator design pattern. Refer: https://github.com/tmrts/go-patterns/blob/master/concurrency/generator.md
func GroupBy ¶
func GroupBy[T any, U comparable](collection []T, iteratee func(item T, index int) U) map[U][]T
GroupBy returns an object composed of keys generated from the results of running each element of collection through iteratee.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := GroupBy(list, func(item int64, index int) int64 { return item % 2 }) fmt.Printf("%+v", result)
Output: map[0:[2 4] 1:[1 3 5]]
func Head ¶
Head returns first element in the collection. If the collection is empty, return zero value of T and false.
Example ¶
list := []int64{1, 2, 3, 4, 5} result, ok := Head(list) fmt.Printf("%+v\n", result) fmt.Printf("%+v\n", ok)
Output: 1 true
func If ¶
Example ¶
result1 := If(true, 1). Else(2) result2 := If(false, 1). Else(2) fmt.Printf("%+v %+v", result1, result2)
Output: 1 2
func IfF ¶
Example ¶
result1 := IfF(true, func() int { return 1 }). ElseF(func() int { return 2 }) result2 := IfF(false, func() int { return 1 }). ElseF(func() int { return 2 }) fmt.Printf("%+v %+v", result1, result2)
Output: 1 2
func Initial ¶
func Initial[T any](collection []T) []T
Initial returns all but the last element of the collection.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := Initial(list) fmt.Printf("%+v", result)
Output: [1 2 3 4]
func Interleave ¶
func Interleave[T any](collections ...[]T) []T
Interleave round-robin alternating input slices and sequentially appending value at index into result.
Example ¶
list := [][]int64{{1, 2}, {3, 4}, {5}, {6, 7, 8}} result := Interleave(list...) fmt.Printf("%+v", result)
Output: [1 3 5 6 2 4 7 8]
func Intersect ¶
func Intersect[T comparable](list1 []T, list2 []T) []T
Intersect returns intersection of list1 and list2
func Invert ¶
func Invert[K comparable, V comparable](in map[K]V) map[V]K
Invert returns a map whose keys are values in in-map, and values are keys in in-map.
Example ¶
result := Invert(exampleMap) fmt.Printf("%+v", sprintSortedMapByKey(result))
Output: map[10:apple 12:orange 15:banana]
func IsNotZero ¶
func IsNotZero[T comparable](x T) bool
IsNotZero returns true if x not equals to zero value of T.
Example ¶
result := IsNotZero[int](1) fmt.Println(result)
Output: true
func IsZero ¶
func IsZero[T comparable](x T) bool
IsZero returns true if x equals to zero value of T.
Example ¶
result := IsZero[int](1) fmt.Println(result)
Output: false
func Join ¶
Join converts all elements in array into a string separated by separator TODO(@wangli) thinking about how to check if T is string
Example ¶
list := []int64{1, 2, 3, 4, 5} result := Join(list, ",") fmt.Printf("%+v", result)
Output: 1,2,3,4,5
func KeyBy ¶
func KeyBy[K comparable, V any](collection []V, iteratee func(v V, index int) K) map[K]V
KeyBy transforms a slice to a map based on a pivot callback.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := KeyBy(list, func(item int64, index int) string { return fmt.Sprintf("key-%d", item) }) fmt.Printf("%+v", result)
Output: map[key-1:1 key-2:2 key-3:3 key-4:4 key-5:5]
func Keys ¶
func Keys[K comparable, V any](in map[K]V) []K
Keys return an array of keys in map.
Example ¶
result := Keys(exampleMap) fmt.Printf("%+v", len(result))
Output: 3
func Last ¶
Last returns last element in the collection. If the collection is empty, return zero value of T and false.
Example ¶
list := []int64{1, 2, 3, 4, 5} result, ok := Last(list) fmt.Printf("%+v\n", result) fmt.Printf("%+v\n", ok)
Output: 5 true
func Map ¶
Map manipulates a slice and transforms it into a slice with another type.
Example ¶
list := []int64{1, 2, 3} result := Map(list, func(item int64, index int) string { return strconv.FormatInt(item, 10) }) fmt.Printf("%+v", result)
Output: [1 2 3]
func MapEntries ¶
func MapEntries[K comparable, V any](in map[K]V, iteratee func(k K, v V) (K, V)) map[K]V
MapEntries returns a map whose key-values is generated by iteratee function.
Example ¶
result := MapEntries(exampleMap, func(k string, v int) (string, int) { return "common_key", 0 }) fmt.Printf("%+v", result)
Output: map[common_key:0]
func MapKeys ¶
func MapKeys[K comparable, V any](in map[K]V, iteratee func(k K, v V) K) map[K]V
MapKeys returns a map whose keys is generated by iteratee function.
Example ¶
result := MapKeys(exampleMap, func(k string, v int) string { return "common_key" }) fmt.Printf("%+v", Keys(result))
Output: [common_key]
func MapOverMap ¶
func MapOverMap[K comparable, V any](in map[K]V, iteratee func(k K, v V))
MapOverMap runs iteratee function in all key-values over in-map.
Example ¶
MapOverMap(exampleMap, func(k string, v int) { fmt.Println(k, v) })
Output:
func MapToSlice ¶
func MapToSlice[K comparable, V any, R any](in map[K]V, iteratee func(k K, v V) R) []R
MapToSlice returns an array whose elements are generated by iteratee function.
Example ¶
result := MapToSlice(exampleMap, func(k string, v int) int64 { return 1 }) fmt.Printf("%+v", result)
Output: [1 1 1]
func MapValues ¶
func MapValues[K comparable, V any](in map[K]V, iteratee func(k K, v V) V) map[K]V
MapValues returns a map whose values is generated by iteratee function.
Example ¶
result := MapValues(exampleMap, func(k string, v int) int { return 0 }) fmt.Printf("%+v", Values(result))
Output: [0 0 0]
func Max ¶
func Max[T constraints.Ordered](elements ...T) T
Max return maximum value in elements.
Example ¶
result := Max(1, 2, 3, 6, 5) fmt.Println(result)
Output: 6
func Merge ¶
func Merge[K comparable, V any](ins ...map[K]V) map[K]V
Merge returns a map that contains all key-values on in-maps.
Example ¶
result := Merge( map[string]int{"a": 1, "b": 2}, map[string]int{"c": 3}, ) fmt.Printf("%+v", sprintSortedMapByKey(result))
Output: map[a:1 b:2 c:3]
func Min ¶
func Min[T constraints.Ordered](elements ...T) T
Min return minimum value in elements.
Example ¶
result := Min(7, -1, 3, 6, 7) fmt.Println(result)
Output: -1
func NewDebounce ¶
NewDebounce returns call, flush and cancel function in debounce.
Example ¶
call, flush, _ := NewDebounce(func() { fmt.Println("exec") }, 300*time.Millisecond) wg := sync.WaitGroup{} wg.Add(1) go func() { for i := 0; i < 3; i++ { time.Sleep(100 * time.Millisecond) call() } flush() for i := 0; i < 3; i++ { time.Sleep(100 * time.Millisecond) call() } wg.Done() }() wg.Wait() time.Sleep(500 * time.Millisecond)
Output: exec exec
func None ¶
func None[T comparable](collection []T, subset []T) bool
None returns true if all elements of a subset is NOT contained into a collection or if the subset is empty.
func NoneBy ¶
func NoneBy[T comparable](collection []T, predicate func(item T) bool) bool
NoneBy returns true if predicate function returns false for all elements in the collection or if the subset is empty.
func Nth ¶
Nth returns the element at index `nth` of collection. If `nth` is negative, returns `nth` element from the end. If `nth` is out of slice bound, returns zero-value of T and error.
Example ¶
collection := []int{1, 2, 3, 4, 5} result1, err1 := Nth(collection, 1) result2, err2 := Nth(collection, -1) fmt.Println(result1, err1, result2, err2)
Output: 2 <nil> 5 <nil>
func OmitBy ¶
func OmitBy[K comparable, V any](in map[K]V, predicate func(key K, value V) bool) map[K]V
OmitBy returns a map whose elements the predicate function returns falsey for, from in-map.
Example ¶
result := OmitBy(exampleMap, func(key string, value int) bool { return strings.HasPrefix(key, "or") }) fmt.Printf("%+v ", sprintSortedMapByKey(result))
Output: map[apple:10 banana:15]
func OmitByKeys ¶
func OmitByKeys[K comparable, V any](in map[K]V, keys []K) map[K]V
OmitByKeys returns a map exclude keys in `keys` from in-map.
Example ¶
result := OmitByKeys(exampleMap, []string{"apple"}) fmt.Printf("%+v", sprintSortedMapByKey(result))
Output: map[banana:15 orange:12]
func OmitByValues ¶
func OmitByValues[K comparable, V comparable](in map[K]V, values []V) map[K]V
OmitByValues returns a map exclude values in `values` from in-map.
Example ¶
result := OmitByValues(exampleMap, []int{10}) fmt.Printf("%+v", sprintSortedMapByKey(result))
Output: map[banana:15 orange:12]
func PanicIf ¶
func PanicIf(err error)
Example ¶
package main import ( "errors" "fmt" ) func wrapPanicIf(srcErr error) (err error) { defer func() { if r := recover(); r != nil { if e, ok := r.(error); ok { err = fmt.Errorf("%w", e) } else { err = fmt.Errorf("unknown panic") } } }() PanicIf(srcErr) return nil } func main() { var err error fmt.Println(wrapPanicIf(err)) err = errors.New("example err") fmt.Println(wrapPanicIf(err)) }
Output: <nil> example err
func PartitionBy ¶
func PartitionBy[T any, P comparable](collection []T, iteratee func(item T, index int) P) [][]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 function.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := PartitionBy(list, func(item int64, index int) bool { return item%2 == 0 }) fmt.Printf("%+v", result)
Output: [[1 3 5] [2 4]]
func PickBy ¶
func PickBy[K comparable, V any](in map[K]V, predicate func(key K, value V) bool) map[K]V
PickBy returns a map whose elements the predicate function returns truthy for, from in-map.
Example ¶
result := PickBy(exampleMap, func(key string, value int) bool { return strings.HasPrefix(key, "or") }) fmt.Printf("%+v", sprintSortedMapByKey(result))
Output: map[orange:12]
func PickByKeys ¶
func PickByKeys[K comparable, V any](in map[K]V, keys []K) map[K]V
PickByKeys returns a map include keys in `keys` from in-map.
Example ¶
result := PickByKeys(exampleMap, []string{"apple"}) fmt.Printf("%+v", sprintSortedMapByKey(result))
Output: map[apple:10]
func PickByValues ¶
func PickByValues[K comparable, V comparable](in map[K]V, values []V) map[K]V
PickByValues returns a map include values in `values` from in-map.
Example ¶
result := PickByValues(exampleMap, []int{10}) fmt.Printf("%+v", sprintSortedMapByKey(result))
Output: map[apple:10]
func RandomString ¶
RandomString returns string of utf8-length size, and with char from charset.
Example ¶
result := RandomString(10, AllCharset) fmt.Println(len(result))
Output: 10
func Range ¶
func Range[T constraints.Integer](elementNum int) []T
Range creates a range with abs(elementNum) elements, which starts from 0.
Example ¶
result1 := Range[int64](3) result2 := Range[int64](-3) fmt.Println(result1) fmt.Println(result2)
Output: [0 1 2] [0 -1 -2]
func RangeFrom ¶
func RangeFrom[T constraints.Integer | constraints.Float](from T, elementNum int) []T
RangeFrom creates a range with abs(elementNum) elements, which starts from `from`.
Example ¶
result1 := RangeFrom[int64](8, 3) result2 := RangeFrom[int64](8, -3) fmt.Println(result1) fmt.Println(result2)
Output: [8 9 10] [8 7 6]
func RangeWithStep ¶
func RangeWithStep[T constraints.Integer | constraints.Float](from, step T, elementNum int) []T
RangeWithStep creates a range with abs(elementNum) elements, which starts from `from` and step.
Example ¶
result1 := RangeWithStep[int64](8, 2, 3) result2 := RangeWithStep[int64](8, -2, 3) fmt.Println(result1) fmt.Println(result2)
Output: [8 10 12] [8 6 4]
func Reduce ¶
func Reduce[T any, R any](collection []T, accumulator func(agg R, item T, index int) R, initial R) R
Reduce reduces a collection into a value which is the accumulate result of running each element in collection through accumulator, where each successive invocation is supplied the return value of the previous.
Example ¶
list := Range[int64](101) result := Reduce[int64, int64](list, func(agg int64, item int64, index int) int64 { return agg + item }, 0) fmt.Printf("%+v", result)
Output: 5050
func ReduceRight ¶
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 from right to left.
Example ¶
// reverse list list := []int64{1, 2, 3, 4, 5} result := ReduceRight[int64, []int64](list, func(agg []int64, item int64, index int) []int64 { agg = append(agg, item) return agg }, make([]int64, 0)) fmt.Printf("%+v", result)
Output: [5 4 3 2 1]
func Reject ¶
Reject iterates over elements of collection, returns an array of all elements that predicate function returns falsey for.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := Reject(list, func(item int64, index int) bool { return item%2 == 0 }) fmt.Printf("%+v", result)
Output: [1 3 5]
func Remove ¶
func Remove[T comparable](collection []T, excludedValues ...T) []T
Remove excludes all excludedValues in collection.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := Remove(list, 1, 3) fmt.Printf("%+v", result)
Output: [2 4 5]
func RemoveBy ¶
RemoveBy removes all elements that predicate function returns true in collection.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := RemoveBy(list, func(item int64, index int) bool { return item%2 == 0 }) fmt.Printf("%+v", result)
Output: [1 3 5]
func Repeat ¶
Repeat returns a array of count initial values.
Example ¶
result := Repeat(5, 5) fmt.Printf("%+v", result)
Output: [5 5 5 5 5]
func RepeatBy ¶
RepeatBy returns an array of count values that generated by predicate function.
Example ¶
result := RepeatBy(5, func(index int) int64 { return int64(index) }) fmt.Printf("%+v", result)
Output: [0 1 2 3 4]
func RepeatString ¶
RepeatString repeats the string n times.
Example ¶
result := RepeatString("ab", 3) fmt.Println(result)
Output: ababab
func RepeatWithClone ¶
RepeatWithClone returns an array of count initial cloned values.
Example ¶
result := RepeatWithClone(5, cloneableInt64(5)) fmt.Printf("%+v", result)
Output: [5 5 5 5 5]
func Reverse ¶
func Reverse[T any](collection []T) []T
Reverse reverses array in-place so that the first element become the last, the second element becomes the second to the last, and so on.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := Reverse(list) fmt.Printf("%+v", result)
Output: [5 4 3 2 1]
func RuneLength ¶
RuneLength returns rune count in str.
Example ¶
result := RuneLength("王hha") fmt.Println(result)
Output: 4
func SafelyRun ¶
func SafelyRun(function func()) (err error)
SafelyRun try to catch panic during f-runtime, and transform it into error.
Example ¶
err := SafelyRun(func() { panic(errors.New("example err")) }) fmt.Println(err)
Output:
func Sample ¶
Sample returns a random element in collection. If collection is empty, return zero value and false.
func SampleSize ¶
SampleSize returns n random elements with diffent indexes in collection. TODO(@wangli) make it more efficient.
Example ¶
list := []int64{1, 2, 3, 4, 5, 6, 7} result := SampleSize(list, 2) fmt.Printf("%+v", len(result))
Output: 2
func Shuffle ¶
func Shuffle[T any](collection []T) []T
Shuffle shuffles the values in the collection in-place. Using the Fisher-Yates shuffle algorithm.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := Shuffle(list) fmt.Printf("%+v", len(result))
Output: 5
func Slice ¶
Slice returns a slice of collection from start up to, but not including, end. It's like collection[start:end], but will not panic on overflow.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := Slice(list, 1, 3) fmt.Printf("%+v", result)
Output: [2 3]
func SliceToChannel ¶
SliceToChannel returns a read-only channel of collection items.
func SliceWithCopy ¶
SliceWithCopy returns a copy of slice in collection from start up to, but not including, end.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := SliceWithCopy(list, 1, 3) fmt.Printf("%+v", result)
Output: [2 3]
func SnakeCase ¶
SnakeCase returns snake-case version of input string.
Example ¶
result := SnakeCase("hello, world!") fmt.Println(result)
Output: hello_world
func Some ¶
func Some[T comparable](collection []T, subset []T) bool
Some returns true if at lease one element of a subset is contained into a collection. If the subset is empty Some returns false.
func SomeBy ¶
func SomeBy[T comparable](collection []T, predicate func(item T) bool) bool
SomeBy returns true if predicate function returns true for at least one element in the collection. If the subset is empty SomeBy returns false.
func SubString ¶
SubString returns result with offset and size.
Example ¶
result1 := SubString("abcde", -2, 2) result2 := SubString("abcde", 0, 10) fmt.Println(result1, result2)
Output: de abcde
func Subtract ¶
func Subtract[T comparable](list1 []T, list2 []T) []T
Subtract returns subtraction of list1 and list2, that is result of list1 - list2.
func Sum ¶
func Sum[T constraints.Integer | constraints.Float | constraints.Complex](collection []T) T
Sum returns sum of collection.
Example ¶
result := Sum([]int{1, 2, 3, 4, 5}) fmt.Println(result)
Output: 15
func SumBy ¶
func SumBy[T any, R constraints.Integer | constraints.Float | constraints.Complex](collection []T, iteratee func(t T, index int) R) R
SumBy returns sum of items generated by iteratee function.
Example ¶
result := SumBy([]int{1, 2, 3, 4, 5}, func(t, index int) int { return t + 1 }) fmt.Println(result)
Output: 20
func Switch ¶
func Switch[T any](predicate T) *switchCase[T]
Example ¶
result1 := Switch(1). Case(false, 3). Case(true, 4). Default(0) result2 := Switch(1). Case(false, 3). Case(false, 4). Default(0) result3 := Switch(1). CaseF(false, func(predicate int) int { return 3 }). CaseF(true, func(predicate int) int { return 4 }). DefaultF(func(predicate int) int { return 0 }) result4 := Switch(1). CaseF(false, func(predicate int) int { return 3 }). CaseF(false, func(predicate int) int { return 4 }). DefaultF(func(predicate int) int { return 0 }) fmt.Printf("%+v %+v %+v %v", result1, result2, result3, result4)
Output: 4 0 4 0
func Tail ¶
func Tail[T any](collection []T) []T
Tail returns all but the first element of the collection.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := Tail(list) fmt.Printf("%+v", result)
Output: [2 3 4 5]
func Take ¶
Take creates a slice of n elements taken from the beginning.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := Take(list, 2) fmt.Printf("%+v", result)
Output: [1 2]
func TakeRight ¶
TakeRight creates a slice of n elements taken from the end.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := TakeRight(list, 2) fmt.Printf("%+v", result)
Output: [4 5]
func TakeRightWhile ¶
TakeRightWhile creates a slice of n elements taken from the end. Elements are taken until the predicate function returns falsey.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := TakeRightWhile(list, func(item int64, index int) bool { return item > 3 }) fmt.Printf("%+v", result)
Output: [4 5]
func TakeWhile ¶
TakeWhile creates a slice of n elements taken from the beginning. Elements are taken until the predicate function returns falsey.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := TakeWhile(list, func(item int64, index int) bool { return item < 3 }) fmt.Printf("%+v", result)
Output: [1 2]
func Ternary ¶
Ternary is a one line if-else statement
Example ¶
result1 := Ternary(true, 1, 2) result2 := Ternary(false, 1, 2) fmt.Printf("%+v %+v", result1, result2)
Output: 1 2
func TernaryF ¶
TernaryF is a one line if-else statement whose options are functions.
Example ¶
result1 := TernaryF(true, func() int { return 1 }, func() int { return 2 }) result2 := TernaryF(false, func() int { return 1 }, func() int { return 2 }) fmt.Printf("%+v %+v", result1, result2)
Output: 1 2
func Times ¶
Times invokes the iteratee function n times, returning an array of results of each invocation.
Example ¶
result := Times(5, func(index int) int64 { return int64(index) }) fmt.Printf("%+v", result)
Output: [0 1 2 3 4]
func ToAnySlice ¶
ToAnySlice returns a slice of elements whose types are any, from collection.
Example ¶
collection := []int{1, 2, 3, 4, 5} result := ToAnySlice(collection) fmt.Println(result)
Output: [1 2 3 4 5]
func ToPtr ¶
func ToPtr[T any](x T) *T
ToPtr returns a pointer copy of value.
Example ¶
x := 1 result := ToPtr(x) fmt.Println(*result)
Output: 1
func ToSlicePtr ¶
func ToSlicePtr[T any](collection []T) []*T
ToSlicePtr returns a slice of elements that are pointer copies of collection.
Example ¶
collection := []int{1, 2, 3, 4, 5} ToSlicePtr(collection)
Output:
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.
Example ¶
list := []int64{1, 1, 2, 2, 3, 3} result := Uniq(list) fmt.Printf("%+v", result)
Output: [1 2 3]
func UniqBy ¶
func UniqBy[T any, U comparable](collection []T, iteratee func(item T, index int) U) []T
UniqBy returns a duplicate-free version of an array, in which only the first occurrence of the element is kept. It accepts `iteratee` which is invoked for each element in array to generate the criterion by which uniqueness is computed. The order of result values is determined by the order they occur in the array.
Example ¶
list := []int64{1, 2, 3, 4, 5} result := UniqBy(list, func(item int64, index int) int64 { return item % 2 }) fmt.Printf("%+v", result)
Output: [1 2]
func Unpack10 ¶
func Unpack10[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any](t10 Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)
Unpack10 returns a Tuple10's inner value.
Example ¶
result1, result2, result3, result4, result5, result6, result7, result8, result9, result10 := Unpack10(Tuple10[int, string, bool, float64, string, float64, string, float64, string, float64]{A: 7, B: "b", C: true, D: 3.14, E: "e", F: 3.14, G: "g", H: 3.14, I: "i", J: 3.14}) fmt.Println(result1, result2, result3, result4, result5, result6, result7, result8, result9, result10)
Output: 7 b true 3.14 e 3.14 g 3.14 i 3.14
func Unpack11 ¶
func Unpack11[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any](t11 Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)
Unpack11 returns a Tuple11's inner value.
Example ¶
result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11 := Unpack11(Tuple11[int, string, bool, float64, string, float64, string, float64, string, float64, string]{A: 7, B: "b", C: true, D: 3.14, E: "e", F: 3.14, G: "g", H: 3.14, I: "i", J: 3.14, K: "k"}) fmt.Println(result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11)
Output: 7 b true 3.14 e 3.14 g 3.14 i 3.14 k
func Unpack12 ¶
func Unpack12[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any](t12 Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)
Unpack12 returns a Tuple12's inner value.
func Unpack13 ¶
func Unpack13[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any](t13 Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)
Unpack13 returns a Tuple13's inner value.
func Unpack14 ¶
func Unpack14[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any, T14 any](t14 Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)
Unpack14 returns a Tuple14's inner value.
func Unpack15 ¶
func Unpack15[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any, T14 any, T15 any](t15 Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]) (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
Unpack15 returns a Tuple15's inner value.
func Unpack16 ¶
func Unpack16[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any, T14 any, T15 any, T16 any](t16 Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]) (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16)
Unpack16 returns a Tuple16's inner value.
func Unpack17 ¶
func Unpack17[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any, T14 any, T15 any, T16 any, T17 any](t17 Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]) (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17)
Unpack17 returns a Tuple17's inner value.
func Unpack2 ¶
Unpack2 returns a Tuple2's inner value.
Example ¶
result1, result2 := Unpack2(Tuple2[int, string]{A: 7, B: "b"}) fmt.Println(result1, result2)
Output: 7 b
func Unpack3 ¶
Unpack3 returns a Tuple3's inner value.
Example ¶
result1, result2, result3 := Unpack3(Tuple3[int, string, bool]{A: 7, B: "b", C: true}) fmt.Println(result1, result2, result3)
Output: 7 b true
func Unpack4 ¶
Unpack4 returns a Tuple4's inner value.
Example ¶
result1, result2, result3, result4 := Unpack4(Tuple4[int, string, bool, float64]{A: 7, B: "b", C: true, D: 3.14}) fmt.Println(result1, result2, result3, result4)
Output: 7 b true 3.14
func Unpack5 ¶
func Unpack5[T1 any, T2 any, T3 any, T4 any, T5 any](t5 Tuple5[T1, T2, T3, T4, T5]) (T1, T2, T3, T4, T5)
Unpack5 returns a Tuple5's inner value.
Example ¶
result1, result2, result3, result4, result5 := Unpack5(Tuple5[int, string, bool, float64, string]{A: 7, B: "b", C: true, D: 3.14, E: "e"}) fmt.Println(result1, result2, result3, result4, result5)
Output: 7 b true 3.14 e
func Unpack6 ¶
func Unpack6[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any](t6 Tuple6[T1, T2, T3, T4, T5, T6]) (T1, T2, T3, T4, T5, T6)
Unpack6 returns a Tuple6's inner value.
Example ¶
result1, result2, result3, result4, result5, result6 := Unpack6(Tuple6[int, string, bool, float64, string, float64]{A: 7, B: "b", C: true, D: 3.14, E: "e", F: 3.14}) fmt.Println(result1, result2, result3, result4, result5, result6)
Output: 7 b true 3.14 e 3.14
func Unpack7 ¶
func Unpack7[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any](t7 Tuple7[T1, T2, T3, T4, T5, T6, T7]) (T1, T2, T3, T4, T5, T6, T7)
Unpack7 returns a Tuple7's inner value.
Example ¶
result1, result2, result3, result4, result5, result6, result7 := Unpack7(Tuple7[int, string, bool, float64, string, float64, string]{A: 7, B: "b", C: true, D: 3.14, E: "e", F: 3.14, G: "g"}) fmt.Println(result1, result2, result3, result4, result5, result6, result7)
Output: 7 b true 3.14 e 3.14 g
func Unpack8 ¶
func Unpack8[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any](t8 Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]) (T1, T2, T3, T4, T5, T6, T7, T8)
Unpack8 returns a Tuple8's inner value.
Example ¶
result1, result2, result3, result4, result5, result6, result7, result8 := Unpack8(Tuple8[int, string, bool, float64, string, float64, string, float64]{A: 7, B: "b", C: true, D: 3.14, E: "e", F: 3.14, G: "g", H: 3.14}) fmt.Println(result1, result2, result3, result4, result5, result6, result7, result8)
Output: 7 b true 3.14 e 3.14 g 3.14
func Unpack9 ¶
func Unpack9[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any](t9 Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) (T1, T2, T3, T4, T5, T6, T7, T8, T9)
Unpack9 returns a Tuple9's inner value.
Example ¶
result1, result2, result3, result4, result5, result6, result7, result8, result9 := Unpack9(Tuple9[int, string, bool, float64, string, float64, string, float64, string]{A: 7, B: "b", C: true, D: 3.14, E: "e", F: 3.14, G: "g", H: 3.14, I: "i"}) fmt.Println(result1, result2, result3, result4, result5, result6, result7, result8, result9)
Output: 7 b true 3.14 e 3.14 g 3.14 i
func Unzip10 ¶
func Unzip10[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any](collection []Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10)
Unzip10 returns 10 slices, whose elements come from Tuple10-collection.
Example ¶
collection := []Tuple10[int, string, bool, float64, string, float64, string, float64, string, float64]{ {1, "a", true, 3.14, "e", 3.14, "g", 3.14, "i", 3.14}, {2, "b", false, 2.72, "f", 0, "", 0, "", 0}, {3, "c", false, 0, "", 0, "", 0, "", 0}, } result1, result2, result3, result4, result5, result6, result7, result8, result9, result10 := Unzip10(collection) fmt.Println(result1, result2, result3, result4, result5, result6, result7, result8, result9, result10)
Output: [1 2 3] [a b c] [true false false] [3.14 2.72 0] [e f ] [3.14 0 0] [g ] [3.14 0 0] [i ] [3.14 0 0]
func Unzip11 ¶
func Unzip11[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any](collection []Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11)
Unzip11 returns 11 slices, whose elements come from Tuple11-collection.
Example ¶
collection := []Tuple11[int, string, bool, float64, string, float64, string, float64, string, float64, string]{ {1, "a", true, 3.14, "e", 3.14, "g", 3.14, "i", 3.14, "k"}, {2, "b", false, 2.72, "f", 0, "", 0, "", 0, ""}, {3, "c", false, 0, "", 0, "", 0, "", 0, ""}, } result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11 := Unzip11(collection) fmt.Println(result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11)
Output: [1 2 3] [a b c] [true false false] [3.14 2.72 0] [e f ] [3.14 0 0] [g ] [3.14 0 0] [i ] [3.14 0 0] [k ]
func Unzip12 ¶
func Unzip12[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any](collection []Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12)
Unzip12 returns 12 slices, whose elements come from Tuple12-collection.
func Unzip13 ¶
func Unzip13[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any](collection []Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12, []T13)
Unzip13 returns 13 slices, whose elements come from Tuple13-collection.
func Unzip14 ¶
func Unzip14[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any, T14 any](collection []Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12, []T13, []T14)
Unzip14 returns 14 slices, whose elements come from Tuple14-collection.
func Unzip15 ¶
func Unzip15[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any, T14 any, T15 any](collection []Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12, []T13, []T14, []T15)
Unzip15 returns 15 slices, whose elements come from Tuple15-collection.
func Unzip16 ¶
func Unzip16[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any, T14 any, T15 any, T16 any](collection []Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12, []T13, []T14, []T15, []T16)
Unzip16 returns 16 slices, whose elements come from Tuple16-collection.
func Unzip17 ¶
func Unzip17[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any, T14 any, T15 any, T16 any, T17 any](collection []Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12, []T13, []T14, []T15, []T16, []T17)
Unzip17 returns 17 slices, whose elements come from Tuple17-collection.
func Unzip2 ¶
Unzip2 returns 2 slices, whose elements come from Tuple2-collection.
Example ¶
collection := []Tuple2[int, string]{ {1, "a"}, {2, "b"}, {3, "c"}, } result1, result2 := Unzip2(collection) fmt.Println(result1, result2)
Output: [1 2 3] [a b c]
func Unzip3 ¶
Unzip3 returns 3 slices, whose elements come from Tuple3-collection.
Example ¶
collection := []Tuple3[int, string, bool]{ {1, "a", true}, {2, "b", false}, {3, "c", false}, } result1, result2, result3 := Unzip3(collection) fmt.Println(result1, result2, result3)
Output: [1 2 3] [a b c] [true false false]
func Unzip4 ¶
func Unzip4[T1 any, T2 any, T3 any, T4 any](collection []Tuple4[T1, T2, T3, T4]) ([]T1, []T2, []T3, []T4)
Unzip4 returns 4 slices, whose elements come from Tuple4-collection.
Example ¶
collection := []Tuple4[int, string, bool, float64]{ {1, "a", true, 3.14}, {2, "b", false, 2.72}, {3, "c", false, 0}, } result1, result2, result3, result4 := Unzip4(collection) fmt.Println(result1, result2, result3, result4)
Output: [1 2 3] [a b c] [true false false] [3.14 2.72 0]
func Unzip5 ¶
func Unzip5[T1 any, T2 any, T3 any, T4 any, T5 any](collection []Tuple5[T1, T2, T3, T4, T5]) ([]T1, []T2, []T3, []T4, []T5)
Unzip5 returns 5 slices, whose elements come from Tuple5-collection.
Example ¶
collection := []Tuple5[int, string, bool, float64, string]{ {1, "a", true, 3.14, "e"}, {2, "b", false, 2.72, "f"}, {3, "c", false, 0, ""}, } result1, result2, result3, result4, result5 := Unzip5(collection) fmt.Println(result1, result2, result3, result4, result5)
Output: [1 2 3] [a b c] [true false false] [3.14 2.72 0] [e f ]
func Unzip6 ¶
func Unzip6[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any](collection []Tuple6[T1, T2, T3, T4, T5, T6]) ([]T1, []T2, []T3, []T4, []T5, []T6)
Unzip6 returns 6 slices, whose elements come from Tuple6-collection.
Example ¶
collection := []Tuple6[int, string, bool, float64, string, float64]{ {1, "a", true, 3.14, "e", 3.14}, {2, "b", false, 2.72, "f", 0}, {3, "c", false, 0, "", 0}, } result1, result2, result3, result4, result5, result6 := Unzip6(collection) fmt.Println(result1, result2, result3, result4, result5, result6)
Output: [1 2 3] [a b c] [true false false] [3.14 2.72 0] [e f ] [3.14 0 0]
func Unzip7 ¶
func Unzip7[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any](collection []Tuple7[T1, T2, T3, T4, T5, T6, T7]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7)
Unzip7 returns 7 slices, whose elements come from Tuple7-collection.
Example ¶
collection := []Tuple7[int, string, bool, float64, string, float64, string]{ {1, "a", true, 3.14, "e", 3.14, "g"}, {2, "b", false, 2.72, "f", 0, ""}, {3, "c", false, 0, "", 0, ""}, } result1, result2, result3, result4, result5, result6, result7 := Unzip7(collection) fmt.Println(result1, result2, result3, result4, result5, result6, result7)
Output: [1 2 3] [a b c] [true false false] [3.14 2.72 0] [e f ] [3.14 0 0] [g ]
func Unzip8 ¶
func Unzip8[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any](collection []Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8)
Unzip8 returns 8 slices, whose elements come from Tuple8-collection.
Example ¶
collection := []Tuple8[int, string, bool, float64, string, float64, string, float64]{ {1, "a", true, 3.14, "e", 3.14, "g", 3.14}, {2, "b", false, 2.72, "f", 0, "", 0}, {3, "c", false, 0, "", 0, "", 0}, } result1, result2, result3, result4, result5, result6, result7, result8 := Unzip8(collection) fmt.Println(result1, result2, result3, result4, result5, result6, result7, result8)
Output: [1 2 3] [a b c] [true false false] [3.14 2.72 0] [e f ] [3.14 0 0] [g ] [3.14 0 0]
func Unzip9 ¶
func Unzip9[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any](collection []Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9)
Unzip9 returns 9 slices, whose elements come from Tuple9-collection.
Example ¶
collection := []Tuple9[int, string, bool, float64, string, float64, string, float64, string]{ {1, "a", true, 3.14, "e", 3.14, "g", 3.14, "i"}, {2, "b", false, 2.72, "f", 0, "", 0, ""}, {3, "c", false, 0, "", 0, "", 0, ""}, } result1, result2, result3, result4, result5, result6, result7, result8, result9 := Unzip9(collection) fmt.Println(result1, result2, result3, result4, result5, result6, result7, result8, result9)
Output: [1 2 3] [a b c] [true false false] [3.14 2.72 0] [e f ] [3.14 0 0] [g ] [3.14 0 0] [i ]
func ValueOr ¶
func ValueOr[K comparable, V any](in map[K]V, key K, fallback V) V
ValueOr return value for key in map. If key not exists in map, return fallback value.
Example ¶
result1 := ValueOr(exampleMap, "apple", 11) result2 := ValueOr(exampleMap, "bear", 11) fmt.Printf("%+v %+v", result1, result2)
Output: 10 11
func Values ¶
func Values[K comparable, V any](in map[K]V) []V
Values return an array of values in map.
Example ¶
result := Values(exampleMap) fmt.Printf("%+v", len(result))
Output: 3
Types ¶
type DispatchingStrategy ¶
func DispatchingStrategyWeightedRandom ¶
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 }
func ToEntries ¶
func ToEntries[K comparable, V any](in map[K]V) []Entry[K, V]
ToEntries returns an entries of array in in-map.
Example ¶
result := ToEntries(exampleMap) sort.Sort(entries[string, int](result)) fmt.Printf("%+v", result)
Output: [{Key:apple Value:10} {Key:banana Value:15} {Key:orange Value:12}]
type Tuple10 ¶
type Tuple10[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any] struct { A T1 B T2 C T3 D T4 E T5 F T6 G T7 H T8 I T9 J T10 }
func Pack10 ¶
func Pack10[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any](a T1, b T2, c T3, d T4, e T5, f T6, g T7, h T8, i T9, j T10) Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]
Pack10 returns a Tuple10 instance.
Example ¶
result := Pack10(7, "beautiful number", true, 3.14, "pi", 3.14, "pi", 3.14, "pi", 3.14) fmt.Printf("%+v", result)
Output: {A:7 B:beautiful number C:true D:3.14 E:pi F:3.14 G:pi H:3.14 I:pi J:3.14}
func Zip10 ¶
func Zip10[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, collection5 []T5, collection6 []T6, collection7 []T7, collection8 []T8, collection9 []T9, collection10 []T10) []Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]
Zip10 returns a Tuple10 slice, whose length is max of input collections.
Example ¶
collection1 := []int{1, 2, 3, 4} collection2 := []string{"a", "b", "c"} collection3 := []bool{true, false} collection4 := []float64{3.14, 2.72} collection5 := []string{"e", "f"} collection6 := []float64{3.14} collection7 := []string{"g"} collection8 := []float64{3.14} collection9 := []string{"i"} collection10 := []float64{3.14} result := Zip10(collection1, collection2, collection3, collection4, collection5, collection6, collection7, collection8, collection9, collection10) fmt.Println(result)
Output: [{1 a true 3.14 e 3.14 g 3.14 i 3.14} {2 b false 2.72 f 0 0 0} {3 c false 0 0 0 0} {4 false 0 0 0 0}]
type Tuple11 ¶
type Tuple11[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any] struct { A T1 B T2 C T3 D T4 E T5 F T6 G T7 H T8 I T9 J T10 K T11 }
func Pack11 ¶
func Pack11[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any](a T1, b T2, c T3, d T4, e T5, f T6, g T7, h T8, i T9, j T10, k T11) Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]
Pack11 returns a Tuple11 instance.
Example ¶
result := Pack11(7, "beautiful number", true, 3.14, "pi", 3.14, "pi", 3.14, "pi", 3.14, "pi") fmt.Printf("%+v", result)
Output: {A:7 B:beautiful number C:true D:3.14 E:pi F:3.14 G:pi H:3.14 I:pi J:3.14 K:pi}
func Zip11 ¶
func Zip11[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, collection5 []T5, collection6 []T6, collection7 []T7, collection8 []T8, collection9 []T9, collection10 []T10, collection11 []T11) []Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]
Zip11 returns a Tuple11 slice, whose length is max of input collections.
Example ¶
collection1 := []int{1, 2, 3, 4} collection2 := []string{"a", "b", "c"} collection3 := []bool{true, false} collection4 := []float64{3.14, 2.72} collection5 := []string{"e", "f"} collection6 := []float64{3.14} collection7 := []string{"g"} collection8 := []float64{3.14} collection9 := []string{"i"} collection10 := []float64{3.14} collection11 := []string{"j"} result := Zip11(collection1, collection2, collection3, collection4, collection5, collection6, collection7, collection8, collection9, collection10, collection11) fmt.Println(result)
Output: [{1 a true 3.14 e 3.14 g 3.14 i 3.14 j} {2 b false 2.72 f 0 0 0 } {3 c false 0 0 0 0 } {4 false 0 0 0 0 }]
type Tuple12 ¶
type Tuple12[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any] struct { A T1 B T2 C T3 D T4 E T5 F T6 G T7 H T8 I T9 J T10 K T11 L T12 }
func Pack12 ¶
func Pack12[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any](a T1, b T2, c T3, d T4, e T5, f T6, g T7, h T8, i T9, j T10, k T11, l T12) Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]
Pack12 returns a Tuple12 instance.
func Zip12 ¶
func Zip12[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, collection5 []T5, collection6 []T6, collection7 []T7, collection8 []T8, collection9 []T9, collection10 []T10, collection11 []T11, collection12 []T12) []Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]
Zip12 returns a Tuple12 slice, whose length is max of input collections.
type Tuple13 ¶
type Tuple13[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any] struct { A T1 B T2 C T3 D T4 E T5 F T6 G T7 H T8 I T9 J T10 K T11 L T12 M T13 }
func Pack13 ¶
func Pack13[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any](a T1, b T2, c T3, d T4, e T5, f T6, g T7, h T8, i T9, j T10, k T11, l T12, m T13) Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]
Pack13 returns a Tuple13 instance.
func Zip13 ¶
func Zip13[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, collection5 []T5, collection6 []T6, collection7 []T7, collection8 []T8, collection9 []T9, collection10 []T10, collection11 []T11, collection12 []T12, collection13 []T13) []Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]
Zip13 returns a Tuple13 slice, whose length is max of input collections.
type Tuple14 ¶
type Tuple14[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any, T14 any] struct { A T1 B T2 C T3 D T4 E T5 F T6 G T7 H T8 I T9 J T10 K T11 L T12 M T13 N T14 }
func Pack14 ¶
func Pack14[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any, T14 any](a T1, b T2, c T3, d T4, e T5, f T6, g T7, h T8, i T9, j T10, k T11, l T12, m T13, n T14) Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]
Pack14 returns a Tuple14 instance.
func Zip14 ¶
func Zip14[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any, T14 any](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, collection5 []T5, collection6 []T6, collection7 []T7, collection8 []T8, collection9 []T9, collection10 []T10, collection11 []T11, collection12 []T12, collection13 []T13, collection14 []T14) []Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]
Zip14 returns a Tuple14 slice, whose length is max of input collections.
type Tuple15 ¶
type Tuple15[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any, T14 any, T15 any] struct { A T1 B T2 C T3 D T4 E T5 F T6 G T7 H T8 I T9 J T10 K T11 L T12 M T13 N T14 O T15 }
func Pack15 ¶
func Pack15[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any, T14 any, T15 any](a T1, b T2, c T3, d T4, e T5, f T6, g T7, h T8, i T9, j T10, k T11, l T12, m T13, n T14, o T15) Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]
Pack15 returns a Tuple15 instance.
func Zip15 ¶
func Zip15[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any, T14 any, T15 any](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, collection5 []T5, collection6 []T6, collection7 []T7, collection8 []T8, collection9 []T9, collection10 []T10, collection11 []T11, collection12 []T12, collection13 []T13, collection14 []T14, collection15 []T15) []Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]
Zip15 returns a Tuple15 slice, whose length is max of input collections.
type Tuple16 ¶
type Tuple16[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any, T14 any, T15 any, T16 any] struct { A T1 B T2 C T3 D T4 E T5 F T6 G T7 H T8 I T9 J T10 K T11 L T12 M T13 N T14 O T15 P T16 }
func Pack16 ¶
func Pack16[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any, T14 any, T15 any, T16 any](a T1, b T2, c T3, d T4, e T5, f T6, g T7, h T8, i T9, j T10, k T11, l T12, m T13, n T14, o T15, p T16) Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]
Pack16 returns a Tuple16 instance.
func Zip16 ¶
func Zip16[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any, T14 any, T15 any, T16 any](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, collection5 []T5, collection6 []T6, collection7 []T7, collection8 []T8, collection9 []T9, collection10 []T10, collection11 []T11, collection12 []T12, collection13 []T13, collection14 []T14, collection15 []T15, collection16 []T16) []Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]
Zip16 returns a Tuple16 slice, whose length is max of input collections.
type Tuple17 ¶
type Tuple17[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any, T14 any, T15 any, T16 any, T17 any] struct { A T1 B T2 C T3 D T4 E T5 F T6 G T7 H T8 I T9 J T10 K T11 L T12 M T13 N T14 O T15 P T16 Q T17 }
func Pack17 ¶
func Pack17[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any, T14 any, T15 any, T16 any, T17 any](a T1, b T2, c T3, d T4, e T5, f T6, g T7, h T8, i T9, j T10, k T11, l T12, m T13, n T14, o T15, p T16, q T17) Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]
Pack17 returns a Tuple17 instance.
func Zip17 ¶
func Zip17[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any, T10 any, T11 any, T12 any, T13 any, T14 any, T15 any, T16 any, T17 any](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, collection5 []T5, collection6 []T6, collection7 []T7, collection8 []T8, collection9 []T9, collection10 []T10, collection11 []T11, collection12 []T12, collection13 []T13, collection14 []T14, collection15 []T15, collection16 []T16, collection17 []T17) []Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]
Zip17 returns a Tuple17 slice, whose length is max of input collections.
type Tuple2 ¶
func Pack2 ¶
Pack2 returns a Tuple2 instance.
Example ¶
result := Pack2(7, "beautiful number") fmt.Printf("%+v", result)
Output: {A:7 B:beautiful number}
type Tuple3 ¶
func Pack3 ¶
Pack3 returns a Tuple3 instance.
Example ¶
result := Pack3(7, "beautiful number", true) fmt.Printf("%+v", result)
Output: {A:7 B:beautiful number C:true}
func Zip3 ¶
func Zip3[T1 any, T2 any, T3 any](collection1 []T1, collection2 []T2, collection3 []T3) []Tuple3[T1, T2, T3]
Zip3 returns a Tuple3 slice, whose length is max of input collections.
Example ¶
collection1 := []int{1, 2, 3, 4} collection2 := []string{"a", "b", "c"} collection3 := []bool{true, false} result := Zip3(collection1, collection2, collection3) fmt.Println(result)
Output: [{1 a true} {2 b false} {3 c false} {4 false}]
type Tuple4 ¶
func Pack4 ¶
Pack4 returns a Tuple4 instance.
Example ¶
result := Pack4(7, "beautiful number", true, 3.14) fmt.Printf("%+v", result)
Output: {A:7 B:beautiful number C:true D:3.14}
func Zip4 ¶
func Zip4[T1 any, T2 any, T3 any, T4 any](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4) []Tuple4[T1, T2, T3, T4]
Zip4 returns a Tuple4 slice, whose length is max of input collections.
Example ¶
collection1 := []int{1, 2, 3, 4} collection2 := []string{"a", "b", "c"} collection3 := []bool{true, false} collection4 := []float64{3.14, 2.72} result := Zip4(collection1, collection2, collection3, collection4) fmt.Println(result)
Output: [{1 a true 3.14} {2 b false 2.72} {3 c false 0} {4 false 0}]
type Tuple5 ¶
func Pack5 ¶
func Pack5[T1 any, T2 any, T3 any, T4 any, T5 any](a T1, b T2, c T3, d T4, e T5) Tuple5[T1, T2, T3, T4, T5]
Pack5 returns a Tuple5 instance.
Example ¶
result := Pack5(7, "beautiful number", true, 3.14, "pi") fmt.Printf("%+v", result)
Output: {A:7 B:beautiful number C:true D:3.14 E:pi}
func Zip5 ¶
func Zip5[T1 any, T2 any, T3 any, T4 any, T5 any](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, collection5 []T5) []Tuple5[T1, T2, T3, T4, T5]
Zip5 returns a Tuple5 slice, whose length is max of input collections.
Example ¶
collection1 := []int{1, 2, 3, 4} collection2 := []string{"a", "b", "c"} collection3 := []bool{true, false} collection4 := []float64{3.14, 2.72} collection5 := []string{"e", "f"} result := Zip5(collection1, collection2, collection3, collection4, collection5) fmt.Println(result)
Output: [{1 a true 3.14 e} {2 b false 2.72 f} {3 c false 0 } {4 false 0 }]
type Tuple6 ¶
type Tuple6[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any] struct { A T1 B T2 C T3 D T4 E T5 F T6 }
func Pack6 ¶
func Pack6[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any](a T1, b T2, c T3, d T4, e T5, f T6) Tuple6[T1, T2, T3, T4, T5, T6]
Pack6 returns a Tuple6 instance.
Example ¶
result := Pack6(7, "beautiful number", true, 3.14, "pi", 3.14) fmt.Printf("%+v", result)
Output: {A:7 B:beautiful number C:true D:3.14 E:pi F:3.14}
func Zip6 ¶
func Zip6[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, collection5 []T5, collection6 []T6) []Tuple6[T1, T2, T3, T4, T5, T6]
Zip6 returns a Tuple6 slice, whose length is max of input collections.
Example ¶
collection1 := []int{1, 2, 3, 4} collection2 := []string{"a", "b", "c"} collection3 := []bool{true, false} collection4 := []float64{3.14, 2.72} collection5 := []string{"e", "f"} collection6 := []float64{3.14} result := Zip6(collection1, collection2, collection3, collection4, collection5, collection6) fmt.Println(result)
Output: [{1 a true 3.14 e 3.14} {2 b false 2.72 f 0} {3 c false 0 0} {4 false 0 0}]
type Tuple7 ¶
type Tuple7[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any] struct { A T1 B T2 C T3 D T4 E T5 F T6 G T7 }
func Pack7 ¶
func Pack7[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any](a T1, b T2, c T3, d T4, e T5, f T6, g T7) Tuple7[T1, T2, T3, T4, T5, T6, T7]
Pack7 returns a Tuple7 instance.
Example ¶
result := Pack7(7, "beautiful number", true, 3.14, "pi", 3.14, "pi") fmt.Printf("%+v", result)
Output: {A:7 B:beautiful number C:true D:3.14 E:pi F:3.14 G:pi}
func Zip7 ¶
func Zip7[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, collection5 []T5, collection6 []T6, collection7 []T7) []Tuple7[T1, T2, T3, T4, T5, T6, T7]
Zip7 returns a Tuple7 slice, whose length is max of input collections.
Example ¶
collection1 := []int{1, 2, 3, 4} collection2 := []string{"a", "b", "c"} collection3 := []bool{true, false} collection4 := []float64{3.14, 2.72} collection5 := []string{"e", "f"} collection6 := []float64{3.14} collection7 := []string{"g"} result := Zip7(collection1, collection2, collection3, collection4, collection5, collection6, collection7) fmt.Println(result)
Output: [{1 a true 3.14 e 3.14 g} {2 b false 2.72 f 0 } {3 c false 0 0 } {4 false 0 0 }]
type Tuple8 ¶
type Tuple8[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any] struct { A T1 B T2 C T3 D T4 E T5 F T6 G T7 H T8 }
func Pack8 ¶
func Pack8[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any](a T1, b T2, c T3, d T4, e T5, f T6, g T7, h T8) Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]
Pack8 returns a Tuple8 instance.
Example ¶
result := Pack8(7, "beautiful number", true, 3.14, "pi", 3.14, "pi", 3.14) fmt.Printf("%+v", result)
Output: {A:7 B:beautiful number C:true D:3.14 E:pi F:3.14 G:pi H:3.14}
func Zip8 ¶
func Zip8[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, collection5 []T5, collection6 []T6, collection7 []T7, collection8 []T8) []Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]
Zip8 returns a Tuple8 slice, whose length is max of input collections.
Example ¶
collection1 := []int{1, 2, 3, 4} collection2 := []string{"a", "b", "c"} collection3 := []bool{true, false} collection4 := []float64{3.14, 2.72} collection5 := []string{"e", "f"} collection6 := []float64{3.14} collection7 := []string{"g"} collection8 := []float64{3.14} result := Zip8(collection1, collection2, collection3, collection4, collection5, collection6, collection7, collection8) fmt.Println(result)
Output: [{1 a true 3.14 e 3.14 g 3.14} {2 b false 2.72 f 0 0} {3 c false 0 0 0} {4 false 0 0 0}]
type Tuple9 ¶
type Tuple9[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any] struct { A T1 B T2 C T3 D T4 E T5 F T6 G T7 H T8 I T9 }
func Pack9 ¶
func Pack9[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any](a T1, b T2, c T3, d T4, e T5, f T6, g T7, h T8, i T9) Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]
Pack9 returns a Tuple9 instance.
Example ¶
result := Pack9(7, "beautiful number", true, 3.14, "pi", 3.14, "pi", 3.14, "pi") fmt.Printf("%+v", result)
Output: {A:7 B:beautiful number C:true D:3.14 E:pi F:3.14 G:pi H:3.14 I:pi}
func Zip9 ¶
func Zip9[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any](collection1 []T1, collection2 []T2, collection3 []T3, collection4 []T4, collection5 []T5, collection6 []T6, collection7 []T7, collection8 []T8, collection9 []T9) []Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]
Zip9 returns a Tuple9 slice, whose length is max of input collections.
Example ¶
collection1 := []int{1, 2, 3, 4} collection2 := []string{"a", "b", "c"} collection3 := []bool{true, false} collection4 := []float64{3.14, 2.72} collection5 := []string{"e", "f"} collection6 := []float64{3.14} collection7 := []string{"g"} collection8 := []float64{3.14} collection9 := []string{"i"} result := Zip9(collection1, collection2, collection3, collection4, collection5, collection6, collection7, collection8, collection9) fmt.Println(result)
Output: [{1 a true 3.14 e 3.14 g 3.14 i} {2 b false 2.72 f 0 0 } {3 c false 0 0 0 } {4 false 0 0 0 }]