slices

package
v0.30.36 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

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

Contains checks for the existence of v in s.

func Filter

func Filter[IN any, F FilterFunc[IN]](in []IN, fun F) []IN

Filter filters values from a slice using a filter function. Build returns a new slice with only the elements of s for which f returned true.

func First

func First[IN any](in []IN) (IN, bool)

First returns the First element (or zero value if empty) and bool if exists.

func FlatMap

func FlatMap[IN, OUT any, F FlatMapFunc[IN, OUT]](in []IN, fun F) []OUT

FlatMap turns a []IN to a []OUT using a mapping function. This function has two type parameters, IN and OUT. This works with slices of any type.

func Last

func Last[IN any](in []IN) (IN, bool)

Last returns the Last element (or zero value if empty) and bool if exists.

func Map

func Map[IN, OUT any, F MapFunc[IN, OUT]](in []IN, fun F) []OUT

Map turns a []IN to a []OUT using a mapping function. This function has two type parameters, IN and OUT. This works with slices of any type.

func OfType

func OfType[IN, T any](in []IN) []T

OfType filters values from a slice satisfying a given type.

func Reduce

func Reduce[IN, OUT any](
	in []IN, initializer OUT,
	fun AccumulatorFunc[IN, OUT],
) OUT

Reduce reduces a []IN to a single value using an accumulator function.

func Remove

func Remove[IN comparable](in []IN, items ...IN) []IN

Remove removes all items from the slice in place.

Types

type AccumulatorFunc

type AccumulatorFunc[IN, OUT any] func(out OUT, i int, item IN) OUT

type FilterFunc

type FilterFunc[IN any] interface {
	~func(int, IN) bool | ~func(IN) bool
}

type FlatMapFunc

type FlatMapFunc[IN, OUT any] interface {
	~func(int, IN) []OUT | ~func(IN) []OUT
}

type MapFunc

type MapFunc[IN, OUT any] interface {
	~func(int, IN) OUT | ~func(IN) OUT
}

Jump to

Keyboard shortcuts

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