Documentation ¶
Index ¶
- func Find[T any](it Iterator[T], fn func(T) bool) (T, bool)
- func FindElem[T any](eq cmp.Eq[T]) func(it Iterator[T], e T) (T, bool)
- func FindElemIndex[T any](eq cmp.Eq[T]) func(it Iterator[T], e T) int
- func FindIndex[T any](it Iterator[T], fn func(T) bool) int
- func Fold[T, U any](init T, it Iterator[U], fn func(T, U) T) T
- func ForEach[T any](it Iterator[T], fn func(T))
- func LiftM[T, U any](fn func(T) U) func(Iterator[T]) Iterator[U]
- func Max[T any](ord cmp.Ord[T]) func(it Iterator[T]) (T, bool)
- func MaxBy[T any](it Iterator[T], less func(T, T) bool) (T, bool)
- func Min[T any](ord cmp.Ord[T]) func(it Iterator[T]) (T, bool)
- func MinBy[T any](it Iterator[T], less func(T, T) bool) (T, bool)
- func Sum[T any](m algebra.Monoid[T]) func(it Iterator[T]) T
- func SumWithInit[T any](s algebra.Semigroup[T]) func(init T, it Iterator[T]) T
- type Iterator
- func AndThen[T, U any](x Iterator[T], fn func(T) Iterator[U]) Iterator[U]
- func Filter[T any](it Iterator[T], fn func(T) bool) Iterator[T]
- func FlatMap[T, U any](it Iterator[T], fn func(T) Iterator[U]) Iterator[U]
- func Map[T, U any](it Iterator[T], fn func(T) U) Iterator[U]
- func Pure[T any](x T) Iterator[T]
- func Range[T constraints.Integer](start, end T) Iterator[T]
- func Take[T any](it Iterator[T], n int) Iterator[T]
- func Unfold[T, U any](init T, step func(T) (T, U, bool)) Iterator[U]
- func Zip[T, U any](a Iterator[T], b Iterator[U]) Iterator[pair.Pair[T, U]]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Find ¶
Find returns a first element in `it` that satisfies the given predicate `fn`. It returns `false` as a second return value if no elements are found.
func FindElem ¶
FindElem returns a first element in `it` that equals to `e` in the sense of given `Eq`. It returns `false` as a second return value if no elements are found.
func FindElemIndex ¶
FindElemIndex returns a first index of an element in `it` that equals to `e` in the sense of given `Eq`. It returns negative value if no elements are found.
func FindIndex ¶
FindIndex returns a first index of an element in `it` that satisfies the given predicate `fn`. It returns negative value if no elements are found.
func Max ¶
Max returns the largest element with respect to the given Ord. It returns `<zero value>, false` if the iterator is empty.
func MaxBy ¶
MaxBy returns the largest element with respect to the given function. It returns `<zero value>, false` if the iterator is empty.
func Min ¶
Min returns the smallest element with respect to the given Ord. It returns `<zero value>, false` if the iterator is empty.
func MinBy ¶
MinBy returns the smallest element with respect to the given function. It returns `<zero value>, false` if the iterator is empty.
Types ¶
type Iterator ¶
type Iterator[T any] interface { // Next returns the next element in this Iterable and advances its state. // The second return value is false if and only if there are no elements to return. Next() (T, bool) }
Iterable iterates over some set of elements.
func Range ¶
func Range[T constraints.Integer](start, end T) Iterator[T]
Range returns an Iterator that returns start, start+1, ..., end-1, end, sequentially. The returned Iterator does not return any valeus if end is smaller than start.
func Unfold ¶
Unfold returns an Iterator `it` that has an initial state `init` and updating function `step`. On each call to `it.Next()`, it updates its internal state by applying `step` and return the second return value. If the third return value of `step` is `false`, `it.Next()` stops iterating and returns `(<zero value>, false)`.