enumerator

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2023 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Overview

* Copyright 2023 Christian Sigmon <[email protected]> * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/.

* Copyright 2023 Christian Sigmon <[email protected]> * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/.

* Copyright 2023 Christian Sigmon <[email protected]> * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[V any](e IEnumerable[V], f func(V) bool) bool

All returns true if the given function returns true for all elements in the enumerable.

func Any

func Any[V any](e IEnumerable[V], f func(V) bool) bool

Any returns true if the given function returns true for any element in the enumerable.

func Count

func Count[V any](e IEnumerable[V], f func(V) bool) int

Count returns the number of elements in the enumerable for which the given function returns true.

func Each

func Each[V any](e IEnumerable[V], f func(V))

Each calls the given function for each element in the enumerable.

func ParallelAll

func ParallelAll[V any](e IEnumerable[V], f func(V) bool) bool

ParallelAll returns true if f returns true for all elements of e.

ParallelAll short circuits on the first false return from f.

func ParallelAny

func ParallelAny[V any](e IEnumerable[V], f func(V) bool) bool

ParallelAny returns true if f returns true for any element of e.

ParallelAny short circuits on the first true return from f.

func ParallelCount

func ParallelCount[V any](e IEnumerable[V], f func(V) bool) int

ParallelCount returns the number of elements of e for which f returns true.

func ParallelEach

func ParallelEach[V any](e IEnumerable[V], f func(V))

ParallelEach calls f on each element of e in parallel.

func ParallelReduce

func ParallelReduce[V any, R any](e IEnumerable[V], f func(R, V) R, combiner func([]R) R, initial R) R

ParallelReduce returns a single value by applying the given function f to each element in the enumerable. The combiner function is used to combine the results of each partition of the enumerable.

func Reduce

func Reduce[V any, R any](e IEnumerable[V], f func(R, V) R, initial R) R

Reduce returns a single value by applying the given function to each element in the enumerable.

func SetConcurrency

func SetConcurrency(c int)

SetConcurrency sets the number of goroutines to use for parallel operations. This will impact the number of slice chunks for parallel operations.

Defaults to runtime.NumCPU().

func Sum

func Sum[V number](e IEnumerable[V]) V

Sum returns the sum of all elements in the enumerable.

Types

type IEnumerable

type IEnumerable[V any] interface {
	GetEnumerator() IEnumerator[V]
	ToSlice() []V
}

IEnumerable is the base interface for all collections. It enforces that a structure must provider an enumerator and a way to get a slice of values.

func Filter

func Filter[V any](e IEnumerable[V], f func(V) bool) IEnumerable[V]

Filter returns a new enumerable with only the elements for which the given function returns true.

func GetMapEnumerable

func GetMapEnumerable[K comparable, V any](elements map[K]V) IEnumerable[[2]any]

GetMapValueEnumerable gets an enumerable for the built-in map type's keys and values. The pair is stored in a [2]any array.

func GetMapKeyEnumerable

func GetMapKeyEnumerable[K comparable, V any](elements map[K]V) IEnumerable[K]

GetMapKeyEnumerable gets an enumerable for the built-in map type's keys.

func GetMapValueEnumerable

func GetMapValueEnumerable[K comparable, V any](elements map[K]V) IEnumerable[V]

GetMapValueEnumerable gets an enumerable for the built-in map type's values.

func GetSliceEnumerable

func GetSliceEnumerable[V any](elements []V) IEnumerable[V]

GetSliceEnumerable gets an enumerable for the built-in slice type.

func Map

func Map[V any, R any](e IEnumerable[V], f func(V) R) IEnumerable[R]

Map returns a new enumerable with the given function applied to each element in the enumerable.

func ParallelFilter

func ParallelFilter[V any](e IEnumerable[V], f func(V) bool) IEnumerable[V]

ParallelFilter returns a new IEnumerable with the elements of e for which f returns true.

ParallelFilter preserves order.

func ParallelMap

func ParallelMap[V any, R any](e IEnumerable[V], f func(V) R) IEnumerable[R]

ParallelMap returns a new IEnumerable with the results of applying f to each element of e.

ParallelMap preserves order.

func Range

func Range[V constraints.Integer](start, end V) IEnumerable[V]

Range returns an IEnumerable of integers on the interval [start, end). If end < start, the range will be descending.

type IEnumerator

type IEnumerator[V any] interface {
	Current() V
	Next() bool
	Reset()
}

IEnumerator provides the functionality to enumerate over a collection.

Implementations should be thread safe, with the enumerator acting on a slice copy of the collection.

Jump to

Keyboard shortcuts

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