slice

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT, MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

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

Contains reports whether element is present in slice. Thin wrapper around the stdlib slices.Contains so callers can keep using this package consistently.

func Filter

func Filter[T any](slice []T, predicate function.Predicate[T]) []T

Filter returns a new slice containing only the elements that satisfy predicate. The result is preallocated to the input length to avoid repeated growth in the common case where most elements pass.

func ForEach

func ForEach[T any](ctx context.Context, slice []T, consumer function.Consumer[T])

ForEach applies consumer to each element of slice, fanning out up to NumCPU goroutines. It returns when every element has been processed or ctx is cancelled; in the cancelled case in-flight goroutines are still awaited.

func Map

func Map[S any, T any](ctx context.Context, slice []S, fn function.Function[S, T]) []T

Map applies fn to each element of slice in parallel and returns the results in input order. If ctx is cancelled, untouched slots are left zero-valued.

func Reduce

func Reduce[T any](slice []T, operator function.Operator[T]) T

Reduce folds slice left-to-right using operator. Panics on an empty slice; callers should guard accordingly.

Types

This section is empty.

Jump to

Keyboard shortcuts

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