util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[T any](s []T, predicate func(T) bool) bool

All returns true if all elements satisfy the predicate. Returns true for empty slices.

func Any

func Any[T any](s []T, predicate func(T) bool) bool

Any returns true if any element satisfies the predicate.

func Contains

func Contains[T comparable](s []T, v T) bool

Contains checks if a slice contains a value. Uses == for comparison, so T must be comparable.

func Filter

func Filter[T any](s []T, keep func(T) bool) []T

Filter returns a new slice containing only elements that satisfy the predicate. Returns nil if the input slice is nil.

func Find

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

Find returns the first element that satisfies the predicate. Returns the zero value of T and false if no element is found.

func Map

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

Map transforms a slice using a mapping function. Returns nil if the input slice is nil.

func Partition

func Partition[T any](s []T, predicate func(T) bool) ([]T, []T)

Partition splits a slice into two based on a predicate. The first slice contains elements where predicate returns true, the second contains elements where it returns false. Returns (nil, nil) if the input slice is nil.

func Reduce

func Reduce[T, U any](s []T, initial U, reduce func(U, T) U) U

Reduce accumulates values using a reducer function. The reducer function takes an accumulator and the current element, and returns the new accumulator value.

Types

This section is empty.

Jump to

Keyboard shortcuts

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