Documentation
¶
Index ¶
- func Collect[E any, S ~[]E](ctx context.Context, dst S, iter Iterator[E]) S
- func CollectMap[K comparable, V any, M ~map[K]V](ctx context.Context, dst M, iter Pairs[K, V])
- func CollectN[E any, S ~[]E](ctx context.Context, dst S, iter Iterator[E], n int) S
- func CollectSet[K comparable, V any, M ~map[K]V](ctx context.Context, dst M, iter Iterator[K], value V)
- func Count[E comparable](ctx context.Context, iter Iterator[E], value E) int
- func CountFn[E any](ctx context.Context, iter Iterator[E], fn func(E) bool) int
- func Drain[E any](ctx context.Context, iter Iterator[E])
- func ForEach[E any](ctx context.Context, iter Iterator[E], fn func(value E) bool)
- type Chan
- type Fn
- type Iterator
- func Always[E any](value E) Iterator[E]
- func Chain[E any](iters ...Iterator[E]) Iterator[E]
- func Compact[E comparable](iter Iterator[E]) Iterator[E]
- func CompactFn[E any](iter Iterator[E], fn func(a, B E) bool) Iterator[E]
- func Empty[E any]() Iterator[E]
- func Filter[E any](iter Iterator[E], fn func(E) bool) Iterator[E]
- func Range[N Number](from, to N) Iterator[N]
- func RangeStep[N Number](from, to, step N) Iterator[N]
- func StopOnCancel[E any](iter Iterator[E]) Iterator[E]
- func Tap[E any](iter Iterator[E], fn func(E, bool)) Iterator[E]
- func Transduce[F, T any](iter Iterator[F], fn func(F) T) Iterator[T]
- func TransduceFilter[F, T any](iter Iterator[F], fn func(F) (T, bool)) Iterator[T]
- type IteratorCloser
- type IteratorErr
- type Number
- type Pair
- type Pairs
- type PairsSized
- type Sized
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectMap ¶
func CollectMap[K comparable, V any, M ~map[K]V](ctx context.Context, dst M, iter Pairs[K, V])
func CollectN ¶
CollectN pulls a most n values from iter into dst slice. It will stop if iter is drained.
func CollectSet ¶
func CollectSet[K comparable, V any, M ~map[K]V](ctx context.Context, dst M, iter Iterator[K], value V)
Types ¶
type Chan ¶
type Chan[E any] <-chan E
Chan wraps a read-only channel.
type Fn ¶
Fn is a the most simple iterator - hook, which can be called multiple times until drained.
type Iterator ¶
type Iterator[E any] interface { // Next returns false if there is no more values in the sequence. // Iterator can ignore provided context or return false if context is canceled. Next(ctx context.Context) (_ E, ok bool) }
Iterator is a generic stateful of values.
func Chain ¶
Chain pulls values from provided iterators. It will return false after last iterator is drained.
func Compact ¶
func Compact[E comparable](iter Iterator[E]) Iterator[E]
func Filter ¶
Filter pulls values from iter and filters them using provided fn. Output iterator emits only `fn(value)==true` values.
func Range ¶
Range emits a bounded sequence of numbers [from, to). If from<to, then it's equal to RangeStep(from, to, 1). If from>to, then returns an empty iterator.
func RangeStep ¶
RangeStep emits a bounded sequence of numbers [from, to). Returns non-empty iterator if from<to && step>0 or from>to && step<0. Returns an empty iterator otherwise. Returns an empty iterator if any of arguments is NaN.
func StopOnCancel ¶
StopOnCancel returns false if context is canceled.
func Transduce ¶
Transduce maps values of type F to values of T using provided function fn. If input iter is drained, then output iterator will return false.
func TransduceFilter ¶
TransduceFilter maps values of type F to values of T using provided function fn. If fn returns false, then corresponding result is skipped. If input iter is drained, then output iterator will return false.
type IteratorCloser ¶
IteratorCloser describes an iterator, which can be closed. Multiple close method calls are a valid usage and must not panic. After first method close call the instance of iterator must return false from Next method.
func Closer ¶
func Closer[E any](iter Iterator[E]) IteratorCloser[E]
Closer makes provided iter closable. If provided iter is a closer already, then it returned as is. If it's not, then returned iterator will always return false after method close is called.
type IteratorErr ¶
IteratorErr describes an iterator, which can enter an erroneous state. If there is an error condition, then the Err method must return a non-nil error.
func TransduceErr ¶
func TransduceErr[F, T any](iter Iterator[F], fn func(F) (T, error)) IteratorErr[T]
type Number ¶
type Number interface { constraints.Signed | constraints.Unsigned | constraints.Float }
Number describes a generic integer or float number.
type Pairs ¶
Pair describes a sequence of pairs.
func Enumerate ¶
Enumerate assignes a sequential increasing number starting from 0 to values from provided iterator.
func TransduceArg ¶
TransduceArg maps values of type F to values of T using provided function fn. If input iter is drained, then output iterator will return false. Results of fn are attached to corresponding arguments of fn.
func TransduceErrWrap ¶
type PairsSized ¶
Pair describes a sequence of pairs with known size.
func Map ¶
func Map[K comparable, V any, M ~map[K]V](m M) PairsSized[K, V]
Map returns a sequence of key-value pairs from provided map. Resulting iterator follows the same iteration semantics as a range statement