slices

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: Apache-2.0 Imports: 2 Imported by: 23

Documentation

Index

Constants

View Source
const DefaultParallelism = 5

DefaultParallelism default parallelism for par

Variables

This section is empty.

Functions

func All

func All[T any](arr []T, fn func(T) bool) bool

All checks if all items satisfy the condition function

func Any

func Any[T any](arr []T, fn func(T) bool) bool

Any checks if any item satisfy the condition function

func Contains

func Contains[T comparable](arr []T, pivot T) bool

Contains test if target array contains pivot If T is a pointer, T needs to implement Equal(T) function, otherwise the pointer address If T is not a pointer, T could be either

func Count

func Count[T any](arr []T, fn func(T) bool) int

Count checks how many items satisfy the condition function

func Filter

func Filter[T any](arr []T, fn func(T) bool) []T

Filter functional filter for array items

func Find

func Find[T any](arr []T, fn func(T) bool) *T

Find search the first item with function

func Flatten

func Flatten[T any](arr [][]T) []T

Flatten the given arr

func GroupBy

func GroupBy[T any, V comparable](arr []T, fn func(T) V) map[V][]T

GroupBy group by array items with given projection function

func Index

func Index[T any](arr []T, fn func(T) bool) int

Index search the index of array item with function

func Intersect added in v1.9.0

func Intersect[T comparable](a, b []T) (arr []T)

Intersect calculate the intersection of two array

func IterToArray

func IterToArray[U any, V any, T Iterable[U, V]](iter T) []V

IterToArray convert iterable to list. Next() should be called to get the first item

func Map

func Map[T any, V any](arr []T, fn func(T) V) []V

Map functional conversion for array items

func ParFor

func ParFor[T any](arr []T, fn func(T), opts ...ParOption)

ParFor run parallel executions for items in arr

func ParMap

func ParMap[T any, V any](arr []T, fn func(T) V, opts ...ParOption) []V

ParMap run parallel mapping functions for arr, returned values are ordered

func Reduce

func Reduce[T any, V any](arr []T, reduce func(V, T) V, v V) V

Reduce array

func Sort

func Sort[T any](arr []T, cmp func(T, T) bool)

Sort given array

func Subtract added in v1.9.0

func Subtract[T comparable](a, b []T) (arr []T)

Subtract calculate the subtraction of two array

func Union added in v1.9.0

func Union[T comparable](a, b []T) (arr []T)

Union calculate the union of two array

Types

type Iterable

type Iterable[T any, V any] interface {
	Next() bool
	Value() V
	*T
}

Iterable .

type ParConfig

type ParConfig struct {
	// contains filtered or unexported fields
}

ParConfig config for par execution

func NewParConfig

func NewParConfig(opts ...ParOption) *ParConfig

NewParConfig build config for par execution

type ParOption

type ParOption interface {
	ApplyTo(*ParConfig)
}

ParOption options for par execution

type Parallelism

type Parallelism int

Parallelism specify the parallelism of par execution

func (Parallelism) ApplyTo

func (in Parallelism) ApplyTo(cfg *ParConfig)

ApplyTo .

Jump to

Keyboard shortcuts

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