lo

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: Apache-2.0, BSD-2-Clause Imports: 3 Imported by: 17

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind[FirstParamType, ParamType, ReturnType any](secondParam ParamType, callback func(FirstParamType, ParamType) ReturnType) func(FirstParamType) ReturnType

Bind generates a call wrapper with the second parameter's value fixed.

func Comparator

func Comparator[T constraints.Ordered](a, b T) int

Comparator is a generic comparator for two values. It returns 0 if the two values are equal, -1 if the first value is smaller and 1 if the first value is larger.

func Compare

func Compare[A constraints.Ordered](a, b A) int

Compare returns -1, 0 or 1 if the first parameter is smaller, equal or greater than the second argument.

func Cond

func Cond[T any](condition bool, trueValue, falseValue T) T

Cond is a conditional statement that returns the trueValue if the condition is true and the falseValue otherwise.

func CopySlice

func CopySlice[T any](base []T) (copied []T)

CopySlice copies the base slice into copied and returns the copy.

func Filter

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

Filter iterates over elements of collection, returning an array of all elements predicate returns truthy for.

func FilterByValue

func FilterByValue[K comparable, V any](collection map[K]V, predicate func(V) bool) map[K]V

FilterByValue iterates over the map, returning a map of all elements predicate returns truthy for.

func ForEach

func ForEach[T any](collection []T, iteratee func(T))

ForEach iterates over elements of collection and invokes iteratee for each element.

func KeyBy

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

KeyBy transforms a slice or an array of structs to a map based on a pivot callback.

func KeyOnlyBy

func KeyOnlyBy[K comparable, V any](collection []V, iteratee func(V) K) map[K]types.Empty

KeyOnlyBy transforms a slice or an array of structs to a map containing the keys based on a pivot callback.

func Keys

func Keys[K comparable, V any](in map[K]V) []K

Keys creates an array of the map keys.

func Map

func Map[SourceType any, TargetType any](source []SourceType, mapper func(SourceType) TargetType) (target []TargetType)

Map iterates over elements of collection, applies the mapper function to each element and returns an array of modified TargetType elements.

func Max

func Max[T constraints.Ordered](collection ...T) T

Max returns the maximum value of the collection.

func MergeMaps

func MergeMaps[K comparable, V any](base, update map[K]V) map[K]V

MergeMaps updates the base map with values from the update map and returns the extended base map.

func Min

func Min[T constraints.Ordered](collection ...T) T

Min returns the minimum value of the collection.

func PanicOnErr

func PanicOnErr[T any](result T, err error) T

PanicOnErr panics of the seconds parameter is an error and returns the first parameter otherwise.

func Reduce

func Reduce[T any, R any](collection []T, accumulator func(R, T) 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.

func ReduceProperty

func ReduceProperty[A, B, C any](collection []A, propertyResolver func(A) B, accumulator func(C, B) C, initial C) C

ReduceProperty reduces collection to a value which is the accumulated result of running each element in collection through property resolver, which extracts a value to be reduced from the type, and then accumulator, where each successive invocation is supplied the return value of the previous.

func Return1

func Return1[A any](a A, _ ...any) A

Return1 returns the first parameter out of a set of variadic arguments.

func Return2

func Return2[A any](_ any, a A, _ ...any) A

Return2 returns the second parameter out of a set of variadic arguments.

func Return3

func Return3[A any](_, _ any, a A, _ ...any) A

Return3 returns the third parameter out of a set of variadic arguments.

func Return4

func Return4[A any](_, _, _ any, a A, _ ...any) A

Return4 returns the 4th parameter out of a set of variadic arguments..

func Return5

func Return5[A any](_, _, _, _ any, a A, _ ...any) A

Return5 returns the 5th parameter out of a set of variadic arguments.

func Sum

func Sum[T constraints.Numeric](collection ...T) T

Sum returns the sum of the collection.

func Unique

func Unique[T comparable](collection []T) (unique *set.AdvancedSet[T])

Unique returns a set of unique elements from the collection.

func Values

func Values[K comparable, V any](in map[K]V) []V

Values creates an array of the map values.

func Void

func Void[A, B any](f func(A) B) func(A)

Void returns a function that discards the return argument of the given function.

Types

This section is empty.

Jump to

Keyboard shortcuts

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