lo

package
v1.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: Apache-2.0, BSD-2-Clause Imports: 2 Imported by: 18

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 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 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 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 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.

Types

This section is empty.

Jump to

Keyboard shortcuts

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