slices

package
v0.30.103 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 3 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 Item added in v0.30.39

func Item[T comparable](t T) func(T) bool

Item create a function that check equality to a supplied literal. It requires comparable items.

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
}

type Safe added in v0.30.39

type Safe[T any] struct {
	// contains filtered or unexported fields
}

Safe is a slice wrapper to provide some concurrent operations. It is optimized for reads using the copy-on-write idiom.

func NewSafe added in v0.30.39

func NewSafe[T any](initial ...T) *Safe[T]

NewSafe create a Safe slice with initial items.

func (*Safe[T]) Append added in v0.30.39

func (s *Safe[T]) Append(items ...T) *Safe[T]

func (*Safe[T]) Delete added in v0.30.39

func (s *Safe[T]) Delete(eq func(T) (bool, bool)) *Safe[T]

func (*Safe[T]) Index added in v0.30.39

func (s *Safe[T]) Index(eq func(T) bool) int

func (*Safe[T]) Insert added in v0.30.39

func (s *Safe[T]) Insert(index int, items ...T) *Safe[T]

func (*Safe[T]) Items added in v0.30.39

func (s *Safe[T]) Items() []T

func (*Safe[T]) Reset added in v0.30.39

func (s *Safe[T]) Reset(items ...T) *Safe[T]

Jump to

Keyboard shortcuts

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