slices

package
v0.0.0-...-608ba51 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// ErrElementNotFound is raised when a Find or Index fails
	ErrElementNotFound = "element not found"
)

Variables

This section is empty.

Functions

func Filter

func Filter[T any](fn comb.Predicate[T]) comb.Comb[[]T, []T]

Filter returns a Comb that filters elements of a slice based on a predicate.

func Find

func Find[T any](fn comb.Predicate[T]) comb.Comb[[]T, T]

Find returns a Comb that finds the first element in a slice that satisfies a predicate.

func FoldLeft

func FoldLeft[In, Out any](
	from Out, fn comb.Folder[In, Out],
) comb.Comb[[]In, Out]

FoldLeft returns a Comb that reduces a slice using a reduction function and an initial value, operating on the elements of the slice from left to right.

func FoldRight

func FoldRight[In, Out any](
	from Out, fn comb.Folder[In, Out],
) comb.Comb[[]In, Out]

FoldRight returns a Comb that reduces a slice using a reduction function and an initial value, operating on the elements of the slice from right to left.

func IndexedFind

func IndexedFind[T any](fn IndexedPredicate[T]) comb.Comb[[]T, T]

IndexedFind returns a Comb that finds the first element in a slice that satisfies an indexed predicate.

func IndexedFoldLeft

func IndexedFoldLeft[In, Out any](
	from Out, fn IndexedFolder[In, Out],
) comb.Comb[[]In, Out]

IndexedFoldLeft returns a Comb that reduces a slice using an indexed reduction function and an initial value, operating on the elements of the slice from left to right.

func IndexedFoldRight

func IndexedFoldRight[In, Out any](
	from Out, fn IndexedFolder[In, Out],
) comb.Comb[[]In, Out]

IndexedFoldRight returns a Comb that reduces a slice using an indexed reduction function and an initial value, operating on the elements of the slice from right to left.

func IndexedMap

func IndexedMap[In, Out any](fn IndexedMapper[In, Out]) comb.Comb[[]In, []Out]

IndexedMap returns a Comb that maps a slice using an indexed mapping function.

func Map

func Map[In, Out any](fn comb.Mapper[In, Out]) comb.Comb[[]In, []Out]

Map returns a Comb that maps a slice using a mapping function.

func Sort

func Sort[T cmp.Ordered]() comb.Comb[[]T, []T]

Sort returns a Comb that sorts a slice.

func SortFunc

func SortFunc[T any](fn Compare[T]) comb.Comb[[]T, []T]

SortFunc returns a Comb that sorts a slice using a custom comparison function.

func SortedMap

func SortedMap[In any, Out cmp.Ordered](
	fn comb.Mapper[In, Out],
) comb.Comb[[]In, []Out]

SortedMap returns a Comb that maps a slice and then sorts it based on the output values.

func SortedMapFunc

func SortedMapFunc[In any, Out cmp.Ordered](
	fn comb.Mapper[In, Out], comp Compare[Out],
) comb.Comb[[]In, []Out]

SortedMapFunc returns a Comb that maps a slice and then sorts it using a custom comparison function.

Types

type Compare

type Compare[T any] func(left T, right T) int

Compare is a function type that compares two values and returns an integer result.

type IndexedFolder

type IndexedFolder[In, Out any] func(acc Out, elem In, idx int) Out

IndexedFolder is a function type that reduces input values to an output value, providing the index of the input within its slice

type IndexedMapper

type IndexedMapper[In, Out any] func(elem In, idx int) Out

IndexedMapper is a function type that maps an input value to an output value, providing the index of the input within its slice

type IndexedPredicate

type IndexedPredicate[T any] func(elem T, idx int) bool

IndexedPredicate is a function type that tests a value against a condition with an index, providing the index of the input within its slice

Jump to

Keyboard shortcuts

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