Documentation ¶
Index ¶
- func Async[T any](f func() T) chan T
- func Chunk[T any](container []T, size int) [][]T
- func Clamp[T constraints.Ordered](value, min, max T) T
- func Contains[T comparable](container []T, value T) bool
- func ContainsBy[T any](container []T, predicate func(T) bool) bool
- func Count[T comparable](container []T, value T) int
- func CountBy[T any](container []T, predicate func(T) bool) int
- func Difference[T comparable](list1, list2 []T) (absent2, absent1 []T)
- func Drop[T any](container []T, n int) []T
- func DropWhile[T any](container []T, predicate func(T) bool) []T
- func Every[T comparable](container, subset []T) bool
- func Filter[T any](container []T, predicate func(T, int) bool) []T
- func Flatten[T any](container [][]T) []T
- func IndexOf[T comparable](container []T, value T) int
- func Intersect[T comparable](list1, list2 []T) []T
- func Last[T any](container []T) (T, error)
- func LastIndexOf[T comparable](container []T, value T) int
- func Nth[T any](container []T, index int) (T, error)
- func Partition[T any, U comparable](container []T, iteratee func(x T) U) [][]T
- func Range[T constraints.Integer | constraints.Float](length T) []int
- func RangeFrom[T constraints.Integer | constraints.Float](begin, length T) []T
- func RangeWithSteps[T constraints.Integer | constraints.Float](begin, end, step T) []T
- func Reject[T any](container []T, predicate func(T, int) bool) []T
- func Reverse[T any](container []T) []T
- func Shuffle[T any](container []T) []T
- func Some[T comparable](container, subset []T) bool
- func Ternary[T any](condition bool, when, otherwise T) T
- func Times[T any](count int, iteratee func(int) T) []T
- func Try(callback func() error) bool
- func TryCatch(callback func() error, catch func())
- func TryCatchWithError(callback func() error, catch func(any))
- func TryWithError(callback func() error) (ok bool, err any)
- func Union[T comparable](list1, list2 []T) []T
- func Uniq[T comparable](container []T) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Async ¶
func Async[T any](f func() T) chan T
Async executes a function in a goroutine and returns the result in a channel.
func Chunk ¶
Chunk returns a container of elements split into groups the length of size.
Notice if container can't be split evenly, the final chunk will be the remaining elements.
func Clamp ¶
func Clamp[T constraints.Ordered](value, min, max T) T
Clamp returns the value within the upper and lower bounds.
func Contains ¶
func Contains[T comparable](container []T, value T) bool
Contains returns true if an element is present in a container.
func ContainsBy ¶
ContainsBy returns true if predicate function return true.
func Count ¶
func Count[T comparable](container []T, value T) int
Count returns the count number of elements in the container that compare equal to value.
func CountBy ¶
CountBy returns the count number of elements in the container for which predicate is true.
func Difference ¶
func Difference[T comparable](list1, list2 []T) (absent2, absent1 []T)
Difference returns the difference between two container.
Notice that absent2 is the container of the element absent from list2. In contrary, absent1 is the container of the element absent from list1.
func Drop ¶
Drop returns a container from which the first n elements of a given container have been removed.
func DropWhile ¶
Drop returns a container from which the first elements of a given container have been removed while the predicate is true.
func Every ¶
func Every[T comparable](container, subset []T) bool
Every returns true if all elements of a subset are contained into a container.
func Filter ¶
Filter returns a container with elements for which the predicate of the given container is true.
func Flatten ¶
func Flatten[T any](container [][]T) []T
Flatten returns a container a single level deep.
func IndexOf ¶
func IndexOf[T comparable](container []T, value T) int
IndexOf returns the index where the first occurrence of a value in a container is found, otherwise -1.
func Intersect ¶
func Intersect[T comparable](list1, list2 []T) []T
Intersect returns the intersection between two container.
func LastIndexOf ¶
func LastIndexOf[T comparable](container []T, value T) int
IndexOf returns the index where the last occurrence of a value in a container is found, otherwise -1.
func Nth ¶
Nth returns the element at index `nth` of container, otherwise error if out of bounds.
Notice if `nth` is negative, the nth element from the end is returned.
func Partition ¶
func Partition[T any, U comparable](container []T, iteratee func(x T) U) [][]T
Partition returns a container of elements split into groups by iteratee.
Notice the order of grouped values is determined by the order they occur in the container.
func Range ¶
func Range[T constraints.Integer | constraints.Float](length T) []int
Range returns a container of integer numbers with the given length.
func RangeFrom ¶
func RangeFrom[T constraints.Integer | constraints.Float](begin, length T) []T
RangeFrom returns a container of integer numbers from begin with specified length.
func RangeWithSteps ¶
func RangeWithSteps[T constraints.Integer | constraints.Float](begin, end, step T) []T
RangeWithSteps returns a container of integer numbers progressing the steps from begin to end.
Notice set the step to zero will return empty container.
func Reject ¶
Reject returns the elements of the container for which the predicate is not true.
Notice this method is the opposite of Filter.
func Shuffle ¶
func Shuffle[T any](container []T) []T
Shuffle returns a container of shuffled values.
Notice the Fisher-Yates shuffle algorithm is implemented.
func Some ¶
func Some[T comparable](container, subset []T) bool
Some returns true if at least 1 element of a subset is contained into a container.
func Ternary ¶
Ternary returns `when` if the condition is true, else `otherwise`.
Notice this is a 1 line if/else statement.
func Times ¶
Times returns a container of the iteratee n times.
Notice the iteratee is invoked with index as argument.
func TryCatch ¶
func TryCatch(callback func() error, catch func())
TryCatch calls the catch function in case of error.
Notice the method has the same behavior than Try, but calls the catch function in case of error.
func TryCatchWithError ¶
TryCatchWithError calls the catch function in case of error. But also returns value passed to panic.
Notice the method has underneath the same behavior than TryWithError, but calls the catch function in case of error.
func TryWithError ¶
TryWithError calls the function and returns false in case of error, otherwise true. But also returns value passed to panic.
Notice the method has the same behavior than Try, but also returns value passed to panic.
func Union ¶
func Union[T comparable](list1, list2 []T) []T
Union returns all distinct elements from both container.
func Uniq ¶
func Uniq[T comparable](container []T) []T
Uniq returns a duplicate-free version of a given container.
Notice only the first occurrence of each element is kept. The order of result values is determined by the order they occur in the container.
Types ¶
This section is empty.