iter

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT, Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllMatch

func AllMatch[T any](seq iter.Seq[T], test types.Predicate[T]) bool

AllMatch reports whether the condition holds.

func AnyMatch

func AnyMatch[T any](seq iter.Seq[T], test types.Predicate[T]) bool

AnyMatch reports whether the condition holds.

func At

func At[T any](it iter.Seq[T], index int) (T, bool)

Return the element at index.

func Average

func Average[T constraintsx.Number](it iter.Seq[T]) T

Returns the average of all the elements in the iterator.

func Chain

func Chain[T any](seqs ...iter.Seq[T]) iter.Seq[T]

Chain returns the result.

func ChannelAll2

func ChannelAll2[C ~chan T, T any](c C) iter.Seq2[int, T]

ChannelAll2 returns the result.

func Collect

func Collect[T any, S any, R any](it iter.Seq[T], collector container.Collector[S, T, R]) R

Collect Collecting via Collector.

func Contains

func Contains[T comparable](it iter.Seq[T], target T) bool

Returns true if the target is included in the iterator.

func Count

func Count[T any](seq iter.Seq[T]) (count int)

Count returns the number of elements.

func Distinct

func Distinct[T any, C comparable](seq iter.Seq[T], f types.UnaryFunction[T, C]) iter.Seq[T]

Distinct returns the result.

func Enumerate

func Enumerate[T any](seq iter.Seq[T]) iter.Seq[types.Pair[int, T]]

Enumerate returns the result.

func Every

func Every[T any](seq iter.Seq[T], test types.Predicate[T]) bool

Every reports whether the condition holds.

func Filter

func Filter[T any](seq iter.Seq[T], test types.Predicate[T]) iter.Seq[T]

Filter returns the result.

func First

func First[T any](seq iter.Seq[T]) (T, bool)

First performs the operation.

func FlatMap

func FlatMap[T, R any](seq iter.Seq[T], flatten types.UnaryFunction[T, iter.Seq[R]]) iter.Seq[R]

FlatMap returns the result.

func Fold

func Fold[T, R any](seq iter.Seq[T], initVal R, acc types.BinaryFunction[R, T, R]) (result R)

Fold performs the operation.

func ForEach

func ForEach[T any](seq iter.Seq[T], accept types.Consumer[T])

ForEach performs the operation.

func IsEmpty

func IsEmpty[T any](it iter.Seq[T]) bool

Ruturns true if the count of Iterator is 0.

func IsNotEmpty

func IsNotEmpty[T any](it iter.Seq[T]) bool

Ruturns true if the count of Iterator is 0.

func IsSorted

func IsSorted[T any](seq iter.Seq[T], cmp types.Comparator[T]) bool

IsSorted reports whether the condition holds.

func IterSeq

func IterSeq[T any](iter Iterator[T]) iter.Seq[T]

IterSeq returns the result.

func JoinBy

func JoinBy[T any](it iter.Seq[T], toString func(T) string, sep string) string

JoinBy returns the result.

func Last

func Last[T any](it iter.Seq[T]) (T, bool)

Return the right element.

func Limit

func Limit[T any](seq iter.Seq[T], limit int) iter.Seq[T]

Limit returns the result.

func Map

func Map[T, R any](seq iter.Seq[T], f types.UnaryFunction[T, R]) iter.Seq[R]

Map returns the result.

func Max

func Max[T constraints.Ordered](it iter.Seq[T]) (T, bool)

Return the maximum value of all elements of the iterator.

func MaxBy

func MaxBy[T any](it iter.Seq[T], greater cmp.LessFunc[T]) (T, bool)

Return the maximum value of all elements of the iterator.

func Mean

func Mean[T constraintsx.Number](seq iter.Seq[T]) float64

Calculate the Mean of a slice of floats

func Merge

func Merge[T any](iters ...iter.Seq[T]) iter.Seq[T]

Merge returns the result.

func Min

func Min[T constraints.Ordered](it iter.Seq[T]) (T, bool)

Return the minimum value of all elements of the iterator.

func Operator

func Operator[T any](seq iter.Seq[T], add types.BinaryOperator[T]) T

Operator returns the result.

func OperatorBy

func OperatorBy[T any](it iter.Seq[T], f types.BinaryOperator[T]) T

OperatorBy returns the result.

func Peek

func Peek[T any](seq iter.Seq[T], accept types.Consumer[T]) iter.Seq[T]

Peek returns the result.

func Product

func Product[T constraintsx.Number](it iter.Seq[T]) T

Returns the product of all the elements in the iterator.

func RangeAll2

func RangeAll2[T constraintsx.Number](begin, end, step T) iter.Seq2[int, T]

RangeAll2 returns the result.

func Reduce

func Reduce[T any](seq iter.Seq[T], acc types.BinaryOperator[T]) (T, bool)

Reduce performs the operation.

func Seq2Keys

func Seq2Keys[K, V any](s iter.Seq2[K, V]) iter.Seq[K]

Seq2Keys returns the result.

func Seq2Seq

func Seq2Seq[K, V any](s iter.Seq2[K, V]) iter.Seq[types.Pair[K, V]]

Seq2Seq returns the result.

func Seq2Values

func Seq2Values[K, V any](s iter.Seq2[K, V]) iter.Seq[V]

Seq2Values returns the result.

func SeqSeq2

func SeqSeq2[T any](seq iter.Seq[T]) iter.Seq2[int, T]

SeqSeq2 returns the result.

func Skip

func Skip[T any](seq iter.Seq[T], skip int) iter.Seq[T]

Skip returns the result.

func Some

func Some[T any](seq iter.Seq[T], test types.Predicate[T]) bool

Some returns the value.

func Sorted

func Sorted[T any](it iter.Seq[T], cmp types.Comparator[T]) iter.Seq[T]

Sorted returns the result.

func StringAll2

func StringAll2[T ~string](input T) iter.Seq2[int, rune]

StringAll2 returns the result.

func Sum

func Sum[T constraintsx.Number](it iter.Seq[T]) T

Returns the sum of all the elements in the iterator.

func SumComparable

func SumComparable[T constraints.Ordered](seq iter.Seq[T]) T

SumComparable returns the result.

func SumCount

func SumCount[T constraintsx.Number](it iter.Seq[T]) (T, int)

Returns the sum of all the elements in the iterator.

func ToMap

func ToMap[K comparable, V any](it iter.Seq[types.Pair[K, V]]) map[K]V

to built-in map.

func ToSlice

func ToSlice[V any](it iter.Seq[V]) []V

ToSlice converts the value.

func Until

func Until[T any](seq iter.Seq[T], match types.Predicate[T]) iter.Seq[T]

Until returns the result.

func UntilComparable

func UntilComparable[T comparable](seq iter.Seq[T], e T) iter.Seq[T]

UntilComparable returns the result.

func Unzip

func Unzip[A any, B any](it iter.Seq[types.Pair[A, B]]) ([]A, []B)

Splitting an iterator whose elements are pair into two lists.

Types

type GoIter

type GoIter[T any] interface {
	Iterator[T]
	Stop()
}

type Iterable

type Iterable[T any] interface {
	Iter() Iterator[T]
}

type Iterator

type Iterator[T any] interface {
	Next() (v T, ok bool)
}

func SeqIter

func SeqIter[T any](seq iter.Seq[T]) Iterator[T]

SeqIter returns the result.

type Seq

type Seq[T any] iter.Seq[T]

func ChannelAll

func ChannelAll[C ~chan T, T any](c C) Seq[T]

ChannelAll returns the result.

func HashMapAll

func HashMapAll[M ~map[K]V, K comparable, V any](m M) Seq[types.Pair[K, V]]

HashMapAll reports whether the condition holds.

func RangeAll

func RangeAll[T constraintsx.Number](begin, end, step T) Seq[T]

RangeAll returns the result.

func SliceAll

func SliceAll[S ~[]T, T any](input S) Seq[types.Pair[int, T]]

SliceAll returns the result.

func SliceAllValues

func SliceAllValues[S ~[]T, T any](input S) Seq[T]

SliceAllValues returns the result.

func SliceBackward

func SliceBackward[S ~[]T, T any](input S) Seq[types.Pair[int, T]]

SliceBackward returns the result.

func SliceBackwardValues

func SliceBackwardValues[S ~[]T, T any](input S) Seq[T]

SliceBackwardValues returns the result.

func StringAll

func StringAll[T ~string](input T) Seq[types.Pair[int, rune]]

StringAll returns the result.

func StringRunes

func StringRunes[T ~string](input T) Seq[rune]

StringRunes returns the result.

func (Seq[T]) All

func (it Seq[T]) All(test types.Predicate[T]) bool

All reports whether the condition holds.

func (Seq[T]) Any

func (it Seq[T]) Any(test types.Predicate[T]) bool

Any reports whether the condition holds.

func (Seq[T]) Collect

func (it Seq[T]) Collect() []T

Collect returns the result.

func (Seq[T]) Count

func (it Seq[T]) Count() int

Count returns the number of elements.

func (Seq[T]) Distinct

func (it Seq[T]) Distinct(f types.UnaryFunction[T, int]) Stream[T]

Distinct returns the result.

func (Seq[T]) Filter

func (it Seq[T]) Filter(test types.Predicate[T]) Stream[T]

Filter returns the result.

func (Seq[T]) First

func (it Seq[T]) First() (T, bool)

First performs the operation.

func (Seq[T]) FlatMap

func (it Seq[T]) FlatMap(f types.UnaryFunction[T, iter.Seq[T]]) Stream[T]

FlatMap returns the result.

func (Seq[T]) Fold

func (it Seq[T]) Fold(initVal T, acc types.BinaryOperator[T]) T

Fold returns the result.

func (Seq[T]) ForEach

func (it Seq[T]) ForEach(accept types.Consumer[T])

ForEach performs the operation.

func (Seq[T]) IsSorted

func (it Seq[T]) IsSorted(cmp types.Comparator[T]) bool

IsSorted reports whether the condition holds.

func (Seq[T]) Iter

func (it Seq[T]) Iter() Iterator[T]

Iter returns the result.

func (Seq[T]) Limit

func (it Seq[T]) Limit(limit int) Stream[T]

Limit returns the result.

func (Seq[T]) Map

func (it Seq[T]) Map(f types.UnaryFunction[T, T]) Stream[T]

Map returns the result.

func (Seq[T]) Peek

func (it Seq[T]) Peek(accept types.Consumer[T]) Stream[T]

Peek returns the result.

func (Seq[T]) Reduce

func (it Seq[T]) Reduce(acc types.BinaryOperator[T]) (T, bool)

Reduce performs the operation.

func (Seq[T]) Seq

func (it Seq[T]) Seq() iter.Seq[T]

Seq returns the result.

func (Seq[T]) Skip

func (it Seq[T]) Skip(skip int) Stream[T]

Skip returns the result.

func (Seq[T]) Sorted

func (it Seq[T]) Sorted(cmp types.Comparator[T]) Stream[T]

Sorted returns the result.

func (Seq[T]) Sum

func (it Seq[T]) Sum(add types.BinaryOperator[T]) T

Sum returns the result.

func (Seq[T]) Until

func (it Seq[T]) Until(test types.Predicate[T]) Stream[T]

Until returns the result.

type Stream

type Stream[T any] interface {
	Seq() iter.Seq[T]

	Filter(types.Predicate[T]) Stream[T]
	Map(types.UnaryFunction[T, T]) Stream[T]               //Same-type conversion; not very useful
	FlatMap(types.UnaryFunction[T, iter.Seq[T]]) Stream[T] //Same as Map
	Peek(types.Consumer[T]) Stream[T]
	Sorted(types.Comparator[T]) Stream[T]
	Distinct(types.UnaryFunction[T, int]) Stream[T]
	Limit(int) Stream[T]
	Until(types.Predicate[T]) Stream[T]
	Skip(int) Stream[T]

	ForEach(types.Consumer[T])
	Collect() []T
	IsSorted(types.Comparator[T]) bool
	All(types.Predicate[T]) bool // every
	Any(types.Predicate[T]) bool // some
	Reduce(acc types.BinaryOperator[T]) (T, bool)
	Fold(initVal T, acc types.BinaryOperator[T]) T
	First() (T, bool)
	Count() int
	Sum(types.BinaryOperator[T]) T
}

func StreamOf

func StreamOf[T any](seq iter.Seq[T]) Stream[T]

StreamOf returns the result.

Jump to

Keyboard shortcuts

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