lo

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: MIT, MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains[T comparable](collection []T, element T) bool

Contains returns true if an element is present in a collection.

func EveryBy

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

EveryBy returns true if the predicate returns true for all of the elements in the collection or if the collection is empty.

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 Find

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

Find search an element in a slice based on a predicate. It returns element and true if element was found.

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 Keys

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

Keys creates an array of the map keys. Play: https://go.dev/play/p/Uu11fHASqrU

func Last

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

Last returns the last element of a collection or error if empty.

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

func Sum[T constraints.Float | constraints.Integer | constraints.Complex](collection []T) T

Sum sums the values in a collection. If collection is empty 0 is returned. Play: https://go.dev/play/p/upfeJVqs4Bt

func Ternary

func Ternary[T any](condition bool, ifOutput, elseOutput T) T

func TernaryF

func TernaryF[T any](condition bool, ifFunc, elseFunc func() T) T

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 Values

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

Values creates an array of the map values. Play: https://go.dev/play/p/nnRTQkzQfF6

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