list

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains[T comparable](haystack []T, needle T) bool

Contains checks if the needle element exists in a given haystack

func Filter

func Filter[T any](list []T, filterFunc func(item T) bool) []T

Filter returns all items which pass the filterFunc

func Find added in v0.2.0

func Find[T any](haystack []T, predicate func(T) bool) (T, bool)

Find finds an element in the haystick by given predicate

func Keys

func Keys[T comparable, U any](m map[T]U) []T

Keys returns all map-keys for the provided map m

func Map

func Map[T, U any](list []T, f func(T) U) []U

Map transforms the list by running the f func on each element in list

func PassEntry added in v0.3.0

func PassEntry[E comparable](e E) E

func Reduce

func Reduce[T, U any](list []T, initial U, f func(T, U) U) U

Reduce maps and reduces f on every list item with the initial U

func ReduceMap

func ReduceMap[K comparable, V, U any](m map[K]V, initial U, f func(K, V, U) U) U

ReduceMap maps and reduces f on every list item with the initial U

func Sort

func Sort[T any](list []T, sortFunc func(l, r T) bool) []T

Sort uses sort.Slice to sort a given list (in-place)

func SortEntries added in v0.3.0

func SortEntries[S ~[]E, E any, C comparable](list S, comparator func(l, r C) int, getter func(E) C) S

func TryMap

func TryMap[T, U any](list []T, f func(T) (U, error)) ([]U, error)

TryMap tries to run f on each element in list, and returns an error if an error happens

Types

This section is empty.

Jump to

Keyboard shortcuts

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