change

package
v0.0.0-...-e3e60e4 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://go.dev/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://go.dev/play/p/EeKl0AuTehH

func Compact

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

Compact returns a slice of all non-zero elements. Play: https://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/play/p/YSoYmQTA8-U

func Flatten

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

Flatten returns an array a single level deep. Play: https://go.dev/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://go.dev/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://go.dev/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://go.dev/play/p/DDhlwrShbwe

func IsSorted

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

IsSorted checks if a slice is sorted. Play: https://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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://go.dev/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