change

package
v0.0.0-...-2fc1e16 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Associate

func Associate[T any, K comparable, V any](collection []T, transform func(item T) (K, V)) map[K]V

Associate returns a map containing key-value pairs provided by transform function applied to elements of the given slice. If any of two pairs would have the same key the last one gets added to the map. The order of keys in returned map is not specified and is not guaranteed to be the same from the original array. Play: https://golang.ir/play/p/WHa2CfMO3Lr

func Chunk

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

Chunk returns an array of elements split into groups the length of size. If array can't be split evenly, the final chunk will be the remaining elements. Play: https://golang.ir/play/p/EeKl0AuTehH

func Compact

func Compact[T comparable](collection []T) []T

Compact returns a slice of all non-zero elements. Play: https://golang.ir/play/p/tXiy-iK6PAc

func Count

func Count[T comparable](collection []T, value T) (count int)

Count counts the number of elements in the collection that compare equal to value. Play: https://golang.ir/play/p/Y3FlK54yveC

func CountBy

func CountBy[T any](collection []T, predicate func(item T) bool) (count int)

CountBy counts the number of elements in the collection for which predicate is true. Play: https://golang.ir/play/p/ByQbNYQQi4X

func CountValues

func CountValues[T comparable](collection []T) map[T]int

CountValues counts the number of each element in the collection. Play: https://golang.ir/play/p/-p-PyLT4dfy

func CountValuesBy

func CountValuesBy[T any, U comparable](collection []T, mapper func(item T) U) map[U]int

CountValuesBy counts the number of each element return from mapper function. Is equivalent to chaining lo.Map and lo.CountValues. Play: https://golang.ir/play/p/2U0dG1SnOmS

func Drop

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

Drop drops n elements from the beginning of a slice or array. Play: https://golang.ir/play/p/JswS7vXRJP2

func DropRight

func DropRight[T any](collection []T, n int) []T

DropRight drops n elements from the end of a slice or array. Play: https://golang.ir/play/p/GG0nXkSJJa3

func DropRightWhile

func DropRightWhile[T any](collection []T, predicate func(item T) bool) []T

DropRightWhile drops elements from the end of a slice or array while the predicate returns true. Play: https://golang.ir/play/p/3-n71oEC0Hz

func DropWhile

func DropWhile[T any](collection []T, predicate func(item T) bool) []T

DropWhile drops elements from the beginning of a slice or array while the predicate returns true. Play: https://golang.ir/play/p/7gBPYw2IK16

func Fill

func Fill[T Clonable[T]](collection []T, initial T) []T

Fill fills elements of array with `initial` value. Play: https://golang.ir/play/p/VwR34GzqEub

func Filter

func Filter[V any](collection []V, predicate func(item V, index int) bool) []V

Filter iterates over elements of collection, returning an array of all elements predicate returns truthy for. Play: https://golang.ir/play/p/Apjg3WeSi7K

func FilterMap

func FilterMap[T any, R any](collection []T, callback func(item T, index int) (R, bool)) []R

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.

Play: https://golang.ir/play/p/-AuYXfy7opz

func FlatMap

func FlatMap[T any, R any](collection []T, iteratee func(item T, index int) []R) []R

FlatMap manipulates a slice and transforms and flattens it to a slice of another type. Play: https://golang.ir/play/p/YSoYmQTA8-U

func Flatten

func Flatten[T any](collection [][]T) []T

Flatten returns an array a single level deep. Play: https://golang.ir/play/p/rbp9ORaMpjw

func ForEach

func ForEach[T any](collection []T, iteratee func(item T, index int))

ForEach iterates over elements of collection and invokes iteratee for each element. Play: https://golang.ir/play/p/oofyiUPRf8t

func GroupBy

func GroupBy[T any, U comparable](collection []T, iteratee func(item T) U) map[U][]T

GroupBy returns an object composed of keys generated from the results of running each element of collection through iteratee. Play: https://golang.ir/play/p/XnQBd_v6brd

func Interleave

func Interleave[T any](collections ...[]T) []T

Interleave round-robin alternating input slices and sequentially appending value at index into result Play: https://golang.ir/play/p/DDhlwrShbwe

func IsSorted

func IsSorted[T constraints.Ordered](collection []T) bool

IsSorted checks if a slice is sorted. Play: https://golang.ir/play/p/mc3qR-t4mcx

func IsSortedByKey

func IsSortedByKey[T any, K constraints.Ordered](collection []T, iteratee func(item T) K) bool

IsSortedByKey checks if a slice is sorted by iteratee. Play: https://golang.ir/play/p/wiG6XyBBu49

func KeyBy

func KeyBy[K comparable, V any](collection []V, iteratee func(item V) K) map[K]V

KeyBy transforms a slice or an array of structs to a map based on a pivot callback. Play: https://golang.ir/play/p/mdaClUAT-zZ

func Map

func Map[T any, R any](collection []T, iteratee func(item T, index int) R) []R

Map manipulates a slice and transforms it to a slice of another type. Play: https://golang.ir/play/p/OkPcYAhBo0D

func PartitionBy

func PartitionBy[T any, K comparable](collection []T, iteratee func(item T) K) [][]T

PartitionBy returns an array of elements split into groups. The order of grouped values is determined by the order they occur in collection. The grouping is generated from the results of running each element of collection through iteratee. Play: https://golang.ir/play/p/NfQ_nGjkgXW

func Reduce

func Reduce[T any, R any](collection []T, accumulator func(agg R, item T, index int) R, initial R) R

Reduce reduces collection to a value which is the accumulated result of running each element in collection through accumulator, where each successive invocation is supplied the return value of the previous. Play: https://golang.ir/play/p/R4UHXZNaaUG

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 of collection from right to left. Play: https://golang.ir/play/p/Fq3W70l7wXF

func Reject

func Reject[V any](collection []V, predicate func(item V, index int) bool) []V

Reject is the opposite of Filter, this method returns the elements of collection that predicate does not return truthy for. Play: https://golang.ir/play/p/YkLMODy1WEL

func Repeat

func Repeat[T Clonable[T]](count int, initial T) []T

Repeat builds a slice with N copies of initial value. Play: https://golang.ir/play/p/g3uHXbmc3b6

func RepeatBy

func RepeatBy[T any](count int, predicate func(index int) T) []T

RepeatBy builds a slice with values returned by N calls of callback. Play: https://golang.ir/play/p/ozZLCtX_hNU

func Replace

func Replace[T comparable](collection []T, old T, new T, n int) []T

Replace returns a copy of the slice with the first n non-overlapping instances of old replaced by new. Play: https://golang.ir/play/p/XfPzmf9gql6

func ReplaceAll

func ReplaceAll[T comparable](collection []T, old T, new T) []T

ReplaceAll returns a copy of the slice with all non-overlapping instances of old replaced by new. Play: https://golang.ir/play/p/a9xZFUHfYcV

func Reverse

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

Reverse reverses array so that the first element becomes the last, the second element becomes the second to last, and so on. Play: https://golang.ir/play/p/fhUMLvZ7vS6

func Shuffle

func Shuffle[T any](collection []T) []T

Shuffle returns an array of shuffled values. Uses the Fisher-Yates shuffle algorithm. Play: https://golang.ir/play/p/Qp73bnTDnc7

func Slice

func Slice[T any](collection []T, start int, end int) []T

Slice returns a copy of a slice from `start` up to, but not including `end`. Like `slice[start:end]`, but does not panic on overflow. Play: https://golang.ir/play/p/8XWYhfMMA1h

func SliceToMap

func SliceToMap[T any, K comparable, V any](collection []T, transform func(item T) (K, V)) map[K]V

SliceToMap returns a map containing key-value pairs provided by transform function applied to elements of the given slice. If any of two pairs would have the same key the last one gets added to the map. The order of keys in returned map is not specified and is not guaranteed to be the same from the original array. Alias of Associate(). Play: https://golang.ir/play/p/WHa2CfMO3Lr

func Subset

func Subset[T any](collection []T, offset int, length uint) []T

Subset returns a copy of a slice from `offset` up to `length` elements. Like `slice[start:start+length]`, but does not panic on overflow. Play: https://golang.ir/play/p/tOQu1GhFcog

func Times

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

Times invokes the iteratee n times, returning an array of the results of each invocation. The iteratee is invoked with index as argument. Play: https://golang.ir/play/p/vgQj3Glr6lT

func Uniq

func Uniq[T comparable](collection []T) []T

Uniq returns a duplicate-free version of an array, in which only the first occurrence of each element is kept. The order of result values is determined by the order they occur in the array. Play: https://golang.ir/play/p/DTzbeXZ6iEN

func UniqBy

func UniqBy[T any, U comparable](collection []T, iteratee func(item T) U) []T

UniqBy returns a duplicate-free version of an array, in which only the first occurrence of each element is kept. The order of result values is determined by the order they occur in the array. It accepts `iteratee` which is invoked for each element in array to generate the criterion by which uniqueness is computed. Play: https://golang.ir/play/p/g42Z3QSb53u

Types

type Clonable

type Clonable[T any] interface {
	Clone() T
}

Clonable defines a constraint of types having Clone() T method.

Jump to

Keyboard shortcuts

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