# README
toolbox - Iterate over slices, maps, channels...
⨠wangliliwang/toolbox
is a Lodash-style Go library based on Go 1.18+ Generics and is inspired by samber/lo and lodash.
š Install
go get github.com/wangliliwang/toolbox
š” Usage
You can import toolbox
using:
import (
"github.com/wangliliwang/toolbox"
)
Then use one of the helpers below:
ch := toolbox.SliceToChannel[string]([]string{"Samuel", "John", "Samuel"})
# Packages
No description provided by the author
# Functions
After creates a function that invokes input `function` once it's called n or more times.
Associate transforms a slice to a map whose key-value pairs are generated by transform function.
Buffer creates a slice of n elements from a channel.
BufferWithTimeout.
CamelCase returns camel-case version of input string.
Capitalize converts the first character of string to upper case, and the remaining to lower case.
ChannelDispatcher distributes messages from input channels into N child channels.
ChannelToSlice returns a slice built from channel items.
Chunk returns an array of elements split into groups the length of size.
ChunkString returns chunks whose lengths are len(size), and from str.
No description provided by the author
Contains returns true if an element present in a collection.
ContainsBy returns true if predicate function return true.
Count returns the number of times of the value.
CountBy returns a map composed of keys generated from iteratee.
DispatchingStrategyFirst distributes messages in a first-non-full manner.
DispatchingStrategyLeast distributes messages in the emptiest channel.
DispatchingStrategyMost distributes messages in the fullest channel.
DispatchingStrategyRandom distributes messages in a random manner.
DispatchingStrategyRoundRobin distributes messages in a rotating sequential manner.
DispatchingStrategyWeightedRandom distributes messages in a weighted manner.
Drop returns a slice with n elements dropped from the beginning of the collection.
DropRight returns a slice with n elements dropped from the end of the collection.
DropRightWhile returns a slice excluding elements dropped from the end.
DropWhile returns a slice excluding elements dropped from the beginning.
Every returns true if all elements of a subset are contained into a collection or if the subset is empty.
EveryBy returns true if predicate function returns true for all elements in the collection or if the collection is empty.
FanIn collects items from multiple channels into a single buffered channel.
FanOut broadcasts all upstream messages to multiple downstream channels.
Fill fills the collection with initial value.
FillWithClone fills the collection with cloned initial value.
Filter iterates over elements of collection, returns an array of all elements that predicate function returns truthy for.
FilterMap returns a slice which obtained after both filtering and mapping using the given callback function.
FindBy returns minimum element in collection by comparison function.
FlatMap manipulates a slice and transforms and flattens it to a slice of another type.
Flatten returns an array of single level deep.
ForEach iterates over collection and invokes iteratee function for each element.
ForEachRight iterates over collection from the end and invokes iteratee function for each element.
FromAnySlice returns a slice of elements whose types are T, from collection.
FromEntries returns a map build by entries.
FromPtr returns the pointer value, or zero if pointer is nil.
FromPtrWithFallback returns the pointer value, or fallback if pointer is nil.
FromSlicePtr returns a slice of elements that are values of collection.
FromSlicePtrWithFallback returns a slice of elements that are values with fallback of collection.
Generator implements the generator design pattern.
GroupBy returns an object composed of keys generated from the results of running each element of collection through iteratee.
Head returns first element in the collection.
No description provided by the author
No description provided by the author
Initial returns all but the last element of the collection.
Interleave round-robin alternating input slices and sequentially appending value at index into result.
Intersect returns intersection of list1 and list2.
Invert returns a map whose keys are values in in-map, and values are keys in in-map.
IsNotZero returns true if x not equals to zero value of T.
IsZero returns true if x equals to zero value of T.
Join converts all elements in array into a string separated by separator TODO(@wangli) thinking about how to check if T is string.
KeyBy transforms a slice to a map based on a pivot callback.
Keys return an array of keys in map.
Last returns last element in the collection.
Map manipulates a slice and transforms it into a slice with another type.
MapEntries returns a map whose key-values is generated by iteratee function.
MapKeys returns a map whose keys is generated by iteratee function.
MapOverMap runs iteratee function in all key-values over in-map.
MapToSlice returns an array whose elements are generated by iteratee function.
MapValues returns a map whose values is generated by iteratee function.
Max return maximum value in elements.
Memoize creates a function that memoize the result of func.
Merge returns a map that contains all key-values on in-maps.
Min return minimum value in elements.
NewDebounce returns call, flush and cancel function in debounce.
None returns true if all elements of a subset is NOT contained into a collection or if the subset is empty.
NoneBy returns true if predicate function returns false for all elements in the collection or if the subset is empty.
Nth returns the element at index `nth` of collection.
OmitBy returns a map whose elements the predicate function returns falsey for, from in-map.
OmitByKeys returns a map exclude keys in `keys` from in-map.
OmitByValues returns a map exclude values in `values` from in-map.
Pack10 returns a Tuple10 instance.
Pack11 returns a Tuple11 instance.
Pack12 returns a Tuple12 instance.
Pack13 returns a Tuple13 instance.
Pack14 returns a Tuple14 instance.
Pack15 returns a Tuple15 instance.
Pack16 returns a Tuple16 instance.
Pack17 returns a Tuple17 instance.
Pack2 returns a Tuple2 instance.
Pack3 returns a Tuple3 instance.
Pack4 returns a Tuple4 instance.
Pack5 returns a Tuple5 instance.
Pack6 returns a Tuple6 instance.
Pack7 returns a Tuple7 instance.
Pack8 returns a Tuple8 instance.
Pack9 returns a Tuple9 instance.
No description provided by the author
PartitionBy returns an array of elements split into groups.
PickBy returns a map whose elements the predicate function returns truthy for, from in-map.
PickByKeys returns a map include keys in `keys` from in-map.
PickByValues returns a map include values in `values` from in-map.
RandomString returns string of utf8-length size, and with char from charset.
Range creates a range with abs(elementNum) elements, which starts from 0.
RangeFrom creates a range with abs(elementNum) elements, which starts from `from`.
RangeWithStep creates a range with abs(elementNum) elements, which starts from `from` and step.
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.
ReduceRight helper is like Reduce except that it iterates over elements from right to left.
Reject iterates over elements of collection, returns an array of all elements that predicate function returns falsey for.
Remove excludes all excludedValues in collection.
RemoveBy removes all elements that predicate function returns true in collection.
Repeat returns a array of count initial values.
RepeatBy returns an array of count values that generated by predicate function.
RepeatString repeats the string n times.
RepeatWithClone returns an array of count initial cloned values.
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.
RuneLength returns rune count in str.
SafelyRun try to catch panic during f-runtime, and transform it into error.
Sample returns a random element in collection.
SampleSize returns n random elements with diffent indexes in collection.
Shuffle shuffles the values in the collection in-place.
Slice returns a slice of collection from start up to, but not including, end.
SliceToChannel returns a read-only channel of collection items.
SliceWithCopy returns a copy of slice in collection from start up to, but not including, end.
SnakeCase returns snake-case version of input string.
Some returns true if at lease one element of a subset is contained into a collection.
SomeBy returns true if predicate function returns true for at least one element in the collection.
SubString returns result with offset and size.
Subtract returns subtraction of list1 and list2, that is result of list1 - list2.
Sum returns sum of collection.
SumBy returns sum of items generated by iteratee function.
No description provided by the author
Tail returns all but the first element of the collection.
Take creates a slice of n elements taken from the beginning.
TakeRight creates a slice of n elements taken from the end.
TakeRightWhile creates a slice of n elements taken from the end.
TakeWhile creates a slice of n elements taken from the beginning.
Ternary is a one line if-else statement.
TernaryF is a one line if-else statement whose options are functions.
Times invokes the iteratee function n times, returning an array of results of each invocation.
ToAnySlice returns a slice of elements whose types are any, from collection.
ToEntries returns an entries of array in in-map.
ToPtr returns a pointer copy of value.
ToSlicePtr returns a slice of elements that are pointer copies of collection.
Union returns union of list.
Uniq returns a duplicate-free version of an array, in which only the first occurrence of each element is kept.
UniqBy returns a duplicate-free version of an array, in which only the first occurrence of the element is kept.
Unpack10 returns a Tuple10's inner value.
Unpack11 returns a Tuple11's inner value.
Unpack12 returns a Tuple12's inner value.
Unpack13 returns a Tuple13's inner value.
Unpack14 returns a Tuple14's inner value.
Unpack15 returns a Tuple15's inner value.
Unpack16 returns a Tuple16's inner value.
Unpack17 returns a Tuple17's inner value.
Unpack2 returns a Tuple2's inner value.
Unpack3 returns a Tuple3's inner value.
Unpack4 returns a Tuple4's inner value.
Unpack5 returns a Tuple5's inner value.
Unpack6 returns a Tuple6's inner value.
Unpack7 returns a Tuple7's inner value.
Unpack8 returns a Tuple8's inner value.
Unpack9 returns a Tuple9's inner value.
Unzip10 returns 10 slices, whose elements come from Tuple10-collection.
Unzip11 returns 11 slices, whose elements come from Tuple11-collection.
Unzip12 returns 12 slices, whose elements come from Tuple12-collection.
Unzip13 returns 13 slices, whose elements come from Tuple13-collection.
Unzip14 returns 14 slices, whose elements come from Tuple14-collection.
Unzip15 returns 15 slices, whose elements come from Tuple15-collection.
Unzip16 returns 16 slices, whose elements come from Tuple16-collection.
Unzip17 returns 17 slices, whose elements come from Tuple17-collection.
Unzip2 returns 2 slices, whose elements come from Tuple2-collection.
Unzip3 returns 3 slices, whose elements come from Tuple3-collection.
Unzip4 returns 4 slices, whose elements come from Tuple4-collection.
Unzip5 returns 5 slices, whose elements come from Tuple5-collection.
Unzip6 returns 6 slices, whose elements come from Tuple6-collection.
Unzip7 returns 7 slices, whose elements come from Tuple7-collection.
Unzip8 returns 8 slices, whose elements come from Tuple8-collection.
Unzip9 returns 9 slices, whose elements come from Tuple9-collection.
ValueOr return value for key in map.
Values return an array of values in map.
Words splits string into an array of its words.
Zero returns zero value of T.
Zip10 returns a Tuple10 slice, whose length is max of input collections.
Zip11 returns a Tuple11 slice, whose length is max of input collections.
Zip12 returns a Tuple12 slice, whose length is max of input collections.
Zip13 returns a Tuple13 slice, whose length is max of input collections.
Zip14 returns a Tuple14 slice, whose length is max of input collections.
Zip15 returns a Tuple15 slice, whose length is max of input collections.
Zip16 returns a Tuple16 slice, whose length is max of input collections.
Zip17 returns a Tuple17 slice, whose length is max of input collections.
Zip2 returns a Tuple2 slice, whose length is max of input collections.
Zip3 returns a Tuple3 slice, whose length is max of input collections.
Zip4 returns a Tuple4 slice, whose length is max of input collections.
Zip5 returns a Tuple5 slice, whose length is max of input collections.
Zip6 returns a Tuple6 slice, whose length is max of input collections.
Zip7 returns a Tuple7 slice, whose length is max of input collections.
Zip8 returns a Tuple8 slice, whose length is max of input collections.
Zip9 returns a Tuple9 slice, whose length is max of input collections.
# Variables
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Interfaces
No description provided by the author
# Type aliases
No description provided by the author