lodash

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

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

func Chunk[T any](container []T, size int) [][]T

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

func ContainsBy[T any](container []T, predicate func(T) bool) bool

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

func CountBy[T any](container []T, predicate func(T) bool) int

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

func Drop[T any](container []T, n int) []T

Drop returns a container from which the first n elements of a given container have been removed.

func DropWhile

func DropWhile[T any](container []T, predicate func(T) bool) []T

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

func Filter[T any](container []T, predicate func(T, int) bool) []T

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 Last

func Last[T any](container []T) (T, error)

Last returns the last element of a container, otherwise error if empty.

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

func Nth[T any](container []T, index int) (T, error)

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

func Reject[T any](container []T, predicate func(T, int) bool) []T

Reject returns the elements of the container for which the predicate is not true.

Notice this method is the opposite of Filter.

func Reverse

func Reverse[T any](container []T) []T

Reverse returns a reverse container.

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

func Ternary[T any](condition bool, when, otherwise T) T

Ternary returns `when` if the condition is true, else `otherwise`.

Notice this is a 1 line if/else statement.

func Times

func Times[T any](count int, iteratee func(int) T) []T

Times returns a container of the iteratee n times.

Notice the iteratee is invoked with index as argument.

func Try

func Try(callback func() error) bool

Try calls the function and returns false in case of error, otherwise true.

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

func TryCatchWithError(callback func() error, catch func(any))

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

func TryWithError(callback func() error) (ok bool, err any)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL