slices

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: BSD-2-Clause Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[T any](in []T, fn func(v T, idx int) bool) bool

All will apply given test func on each input and assert that all of the inputs pass the test. It return on first failed assertion.

func Any

func Any[T any](in []T, fn func(v T, idx int) bool) bool

Any will apply given test func on each input and assert that any of the inputs passes the test. It returns on first succeeded assertion.

func Copy

func Copy[T any](in []T) []T

Copy will return a shallow copy of the input.

func Count

func Count[T any](in []T, fn func(v T, idx int) bool) int

Count will apply a count operation on the input.

func Filter

func Filter[T any](in []T, fn func(v T, idx int) bool) []T

Filter will apply a filter operation on the input.

func FindIndex

func FindIndex[T any](in []T, fn func(v T, idx int) bool) int

FindIndex will search with given test func. When the test is positive it will return its index and `-1` otherwise.

func Map

func Map[T, R any](in []T, fn func(v T, idx int) R) []R

Map will apply a map operation on the input.

func None

func None[T any](in []T, fn func(v T, idx int) bool) bool

None will apply given test func on each input and assert that none of the inputs passes the test. It returns on first failed assertion.

func Range

func Range[T any](in []T, fn func(v T, idx int))

Range will range over given input and apply the given callback func on each element.

func RangeErr

func RangeErr[T any](in []T, fn func(v T, idx int) error) (int, error)

RangeErr will range over given input and apply the given callback func on each element. It will fail on first error, returning the emitted error and the index which failed. If no error was emitted the returned index will be `-1`.

func Reduce

func Reduce[T, R any](in []T, fn func(v T, acc R) R) R

Reduce will apply a reduce operation on the input. The seed value of the accumulator will be its zero value.

func ReduceSeed

func ReduceSeed[T, R any](in []T, seed R, fn func(v T, acc R) R) R

ReduceSeed will apply a reduce operation on the input with given seed value for the accumulator.

func Sort

func Sort[T any](in []T, less func(s []T, i, j int) bool) []T

Sort will sort a shallow copy of the given input based on given "less" func, leaving the input untouched. Within the "less" func you have to use the injected reference of the slice.

func SortStable

func SortStable[T any](in []T, less func(s []T, i, j int) bool) []T

Sort will sort a shallow copy of the given input based on given "less" func, leaving the input untouched. Within the "less" func you have to use the injected reference of the slice.

func SplitBy

func SplitBy[T any](in []T, fn func(v T, idx int) bool) (t []T, f []T)

SplitBy will range over given input and apply the given test func on each element. It will collect all positive results to the first bucket and all negative results in the second.

Types

This section is empty.

Jump to

Keyboard shortcuts

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