aggregate

package
v0.0.0-...-f2fae0e Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[T any](source iterator.Iterator[T], predicate func(T) bool) bool

func Any

func Any[T any](source iterator.Iterator[T], predicate func(T) bool) bool

func Fold

func Fold[T, U any](it iterator.Iterator[T], initial U, fn func(U, T) U) U

Fold applies a function to each element of the iterator, threading an accumulator argument through the computation.

Example
s := source.Slice([]int{1, 2, 3})
it := Fold[int, []int](s, []int{}, func(acc []int, x int) []int { return prependInt(acc, x) })
fmt.Println(it)
Output:

[3 2 1]

func Product

func Product[T Number](it iterator.Iterator[T]) T

Product returns the product of all elements in the iterator.

func Reduce

func Reduce[T any](it iterator.Iterator[T], fn func(T, T) T) T

Reduce applies a function to each element of the iterator, threading an accumulator argument through the computation. The first element of the iterator is used as the initial value of the accumulator. If the iterator is empty, Reduce panics.

func Sum

func Sum[T Number](it iterator.Iterator[T]) T

Sum returns the sum of all elements in the iterator.

Types

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

Number represents any number type that can be aggregated.

Jump to

Keyboard shortcuts

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