Documentation ¶
Index ¶
- func All[T any, I Iterator[T], P ~func(T) bool](it I, predicate P) bool
- func Any[T any, I Iterator[T], P ~func(T) bool](it I, predicate P) bool
- func Collect[T any, I Iterator[T]](it I, n int) []T
- func CollectAll[T any, I Iterator[T]](it I) []T
- func CollectAllInto[T any, I Iterator[T], S ~[]T](it I, result S) S
- func CollectInto[T any, I Iterator[T], S ~[]T](it I, n int, result S) S
- func Find[T any, I Iterator[T], P ~func(T) bool](it I, predicate P) (T, bool)
- func Fold[T, R any, I Iterator[T], F ~func(R, T) R](it I, initial R, f F) R
- func ForEach[T any, I Iterator[T], F ~func(T)](it I, fn F)
- func IsZeroValue[T comparable](value T) bool
- func Max[T constraints.Ordered, I Iterator[T]](it I) optional.Value[T]
- func MaxBy[T any, I Iterator[T], L ~func(T, T) bool](it I, less L) optional.Value[T]
- func MaxValue[T constraints.Ordered](left, right T) T
- func Min[T constraints.Ordered, I Iterator[T]](it I) optional.Value[T]
- func MinBy[T any, I Iterator[T], L ~func(T, T) bool](it I, less L) optional.Value[T]
- func MinValue[T constraints.Ordered](left, right T) T
- func Reduce[T any, I Iterator[T], F ~func(T, T) T](it I, f F) optional.Value[T]
- func ZeroValue[T any]() T
- type CollectorInto
- type Discarder
- type It
- func Chain[T any](its ...Iterator[T]) It[T]
- func Empty[T any]() It[T]
- func Enumerate[T any, I Iterator[T]](it I) It[tuple.T2[Size, T]]
- func Filter[T any, I Iterator[T], P ~func(T) bool](it I, predicate P) It[T]
- func Flatten[T any, I Iterator[Iterator[T]]](it I) It[T]
- func Func[T any, F ~func() (T, bool)](fn F) It[T]
- func New[T any](i Iterator[T]) It[T]
- func Sequence[T constraints.Integer](begin, end T) It[T]
- func Slice[T any](values []T) It[T]
- func Take[T any, I Iterator[T]](it I, n Size) It[T]
- func Transform[T, R any, I Iterator[T], F ~func(T) R](it I, fn F) It[R]
- func Zip[T, U any, I1 Iterator[T], I2 Iterator[U]](i1 I1, i2 I2) It[tuple.T2[T, U]]
- func (i It[T]) All(predicate func(T) bool) bool
- func (i It[T]) Any(predicate func(T) bool) bool
- func (i It[T]) Chain(other ...Iterator[T]) It[T]
- func (i It[T]) Collect(n int) []T
- func (i It[T]) CollectAll() []T
- func (i It[T]) CollectAllInto(result []T) []T
- func (i It[T]) CollectInto(n int, result []T) []T
- func (i It[T]) Discard(n Size) Size
- func (i It[T]) DiscardAll() Size
- func (i It[T]) Filter(predicate func(T) bool) It[T]
- func (i It[T]) Find(predicate func(T) bool) (T, bool)
- func (i It[T]) Iter() Iterator[T]
- func (i It[T]) MaxBy(less func(T, T) bool) optional.Value[T]
- func (i It[T]) MinBy(less func(T, T) bool) optional.Value[T]
- func (i It[T]) Next() (T, bool)
- func (i It[T]) Reduce(f func(T, T) T) optional.Value[T]
- func (i It[T]) SizeHint() (Size, bool)
- func (i It[T]) Take(n Size) It[T]
- type Iterable
- type Iterator
- type LessBuilder
- type Size
- type SizeHinter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All ¶
All tests if every element of the iterator matches a predicate.
It takes a predicate that returns true or false. It applies this predicate to each element of the iterator, and if they all return true, then so does All. If any of them return false, it returns false.
It will stop processing as soon as it finds a false, given that no matter what else happens, the result will also be false.
An empty iterator returns true.
func Any ¶
Any tests if any element of the iterator matches a predicate.
It takes a predicate that returns true or false. It applies this closure to each element of the iterator, and if any of them return true, then so does Any. If they all return false, it returns false.
It will stop processing as soon as it finds a true, given that no matter what else happens, the result will also be true.
An empty iterator returns false.
func CollectAll ¶
CollectAll transforms an iterator into a slice.
func CollectAllInto ¶
CollectAllInto gets all values from an iterator and appends them to a given slice returning the same or a new slice.
func CollectInto ¶
CollectInto gets up to N values from an iterator and appends them to a given slice returning the same or a new slice.
func Find ¶
Find searches for an element of an iterator that satisfies a predicate.
It takes a predicate that returns true or false and applies it to each element of the iterator, and if any of them return true, then Find returns the element and true. If they all return false, it returns zero value and false.
It will stop processing as soon as the predicate returns true.
func Fold ¶
Fold takes initial value as the result value and then applies function F to the result value and and next value from the provided iterator and updates the result value.
func IsZeroValue ¶
func IsZeroValue[T comparable](value T) bool
IsZeroValue returns true if the value is zero initialized.
func Max ¶
func Max[T constraints.Ordered, I Iterator[T]](it I) optional.Value[T]
Max returns maximum value from the iterator if there are any.
func MaxBy ¶
MaxBy returns maximum value from the iterator if there are any. Comparison of two values is performed by the provided less function.
func MaxValue ¶
func MaxValue[T constraints.Ordered](left, right T) T
MaxValue returns maximum value of two values.
func Min ¶
func Min[T constraints.Ordered, I Iterator[T]](it I) optional.Value[T]
Min returns minimum value from the iterator if there are any.
func MinBy ¶
MinBy returns minimum value from the iterator if there are any. Comparison of two values is performed by the provided less function.
func MinValue ¶
func MinValue[T constraints.Ordered](left, right T) T
MinValue returns minimum value of two values.
Types ¶
type CollectorInto ¶
CollectorInto allows collecting items from an iterator in a slice.
type It ¶
type It[T any] struct { // contains filtered or unexported fields }
It is an iterator wrapper that enables shortcuts for composing new iterators.
func Chain ¶
Chain returns an iterator adapter that concatenates the given iterators into a flat iterator of continuous values.
func Enumerate ¶
Enumerate returns an iterator adapter that transform each value into a tuple consisting of its index and the value itself.
func Filter ¶
Filter returns an iterator adapter that filters each value provided by the underlying iterator using the given predicate.
func New ¶
New construct an It that is an iterator wrapper that enables shortcuts for composing new iterators.
func Sequence ¶
func Sequence[T constraints.Integer](begin, end T) It[T]
Sequence returns an iterator that produces consecutive integers from begin to end, end is not included.
func Take ¶
Take returns an iterator that produces up to (but no more than) n values from the input iterator.
func Transform ¶
Transform returns an iterator adapter that transforms each value provided by the underlying iterator using fn.
func Zip ¶
Zip returns an iterator adapter that produces pairs as a tuple of consecutive values from two iterators. In case one of the iterators has next value but other doesn't, Next returns no value. The iterators provided to Zip should not be used anywhere because they may have unpredictable state after usage by Zip due to caching.
func (It[T]) CollectAll ¶
func (i It[T]) CollectAll() []T
func (It[T]) CollectAllInto ¶
func (i It[T]) CollectAllInto(result []T) []T
func (It[T]) CollectInto ¶
func (It[T]) DiscardAll ¶
type LessBuilder ¶
LessBuilder allows to compose various comparison functions based on the stored less function.
func UsingLess ¶
func UsingLess[T any, L ~func(T, T) bool](less L) LessBuilder[T, L]
UsingLess returns a build of comparison functions based on the provided less function.
func (LessBuilder[T, L]) Max ¶
func (b LessBuilder[T, L]) Max() func(T, T) T
Max returns a function that will return a maximum of two values comparing them by the stored less function.
func (LessBuilder[T, L]) Min ¶
func (b LessBuilder[T, L]) Min() func(T, T) T
Min returns a function that will return a minimum of two values comparing them by the stored less function.
type Size ¶
type Size = uint64
Size is a number of items in an iterator or an index of item in iterator.
func Discard ¶
Discard consumes up to n elements from an iterator returning the number of consumed elements.
func DiscardAll ¶
DiscardAll consumes all elements from an iterator returning the number of consumed elements.
type SizeHinter ¶
SizeHinter allows getting estimated remaining number of items in an iterator.