Documentation ¶
Overview ¶
Package to provides utilities to deconstruct or consume iterators down to other types or values.
Index ¶
- func Chan[T any](ctx context.Context, src iter.Seq[T], buf int) <-chan T
- func Contains[T any](src iter.Seq[T], predicate func(T) bool) bool
- func First[T any](src iter.Seq[T], predicate func(T) bool) (t T, found bool)
- func Len[T any](src iter.Seq[T]) int
- func Max[T constraints.Ordered](src iter.Seq[T]) (_ T, ok bool)
- func Min[T constraints.Ordered](src iter.Seq[T]) (_ T, ok bool)
- func Reduce[T any](src iter.Seq[T], startAccum T, ...) (lastAccum T)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Chan ¶
Chan spawns a goroutine that consumes values emitted by the source and sends them on the returned channel. The channel is created with the provided buf size.
Important note: the context cancellation is used to detect when to stop sending data on the returned channel and stop consuming the source, but since the iter.Seq API doesn't support cancellation, the goroutine spawned by Chan will only return once a yield call is performed by the source. Users of Chan should make sure that the source iterator stops when the related context is done.
func Contains ¶
Contains reports whether there is at least one value in the source iterator for which predicate returns true. It stops consuming the source at the first match.
func First ¶
First returns the first value for which predicate returns true and stops consuming src.
func Max ¶
func Max[T constraints.Ordered](src iter.Seq[T]) (_ T, ok bool)
Max returns the maximum element emitted by the source and reports whether at least one value was consumed.
func Min ¶
func Min[T constraints.Ordered](src iter.Seq[T]) (_ T, ok bool)
Min returns the minimum element emitted by the source and reports whether at least one value was consumed.
func Reduce ¶
func Reduce[T any](src iter.Seq[T], startAccum T, predicate func(accum, current T) (newAccum T, ok bool)) (lastAccum T)
Reduce scans the source and applies predicate on all elements it consumes until the predicate returns false or the source is exhausted.
It passes subsequent accumulator values to each call of the predicate and returns the last value for it.
The returned value may be the value for which predicate returned false or the last one before the source was exhausted.
Types ¶
This section is empty.