Documentation
¶
Index ¶
- func AllOf[T any](iter Iter[T], predicate func(T) bool) bool
- func AnyOf[T any](iter Iter[T], predicate func(T) bool) bool
- func Cmp[T cmp.Ordered](iter Iter[T], other Iter[T]) int
- func CmpBy[T any, U any](iter Iter[T], other Iter[U], cmp func(T, U) int) int
- func CmpByKey[T any, K cmp.Ordered](iter Iter[T], other Iter[T], keyFn func(T) K) int
- func CollectInto[T any, E Extend[T]](iter Iter[T], collection E) E
- func CollectToSlice[T any](iter Iter[T]) []T
- func Count[T any](iter Iter[T]) int
- func CountBy[T any](iter Iter[T], predicate func(T) bool) int
- func Equal[T comparable](iter Iter[T], other Iter[T]) bool
- func EqualBy[T, U any](iter Iter[T], other Iter[U], eq func(T, U) bool) bool
- func EqualByKey[T any, K comparable](iter Iter[T], other Iter[T], keyFn func(T) K) bool
- func FindLeft[T any](iter Iter[T], f func(T) bool) optional.Optional[T]
- func FindMap[T, U any](iter Iter[T], f func(T) optional.Optional[U]) optional.Optional[U]
- func FindRight[T any](iter PrevIter[T], f func(T) bool) optional.Optional[T]
- func FoldLeft[T any, A any](iter Iter[T], init A, f func(A, T) A) A
- func FoldRight[T any, A any](iter PrevIter[T], init A, f func(A, T) A) A
- func ForEach[T any](iter Iter[T], f func(T))
- func IsSorted[T cmp.Ordered](iter Iter[T]) bool
- func IsSortedBy[T any](iter Iter[T], cmp func(T, T) int) bool
- func IsSortedByKey[T any, K cmp.Ordered](iter Iter[T], keyFn func(T) K) bool
- func Max[T cmp.Ordered](iter Iter[T]) optional.Optional[T]
- func MaxBy[T any](iter Iter[T], cmp func(T, T) int) optional.Optional[T]
- func MaxByKey[T any, K cmp.Ordered](iter Iter[T], keyFn func(T) K) optional.Optional[T]
- func Min[T cmp.Ordered](iter Iter[T]) optional.Optional[T]
- func MinBy[T any](iter Iter[T], cmp func(T, T) int) optional.Optional[T]
- func MinByKey[T any, K cmp.Ordered](iter Iter[T], keyFn func(T) K) optional.Optional[T]
- func MinMax[T cmp.Ordered](iter Iter[T]) optional.Optional[tuple.Pair[T, T]]
- func MinMaxBy[T any](iter Iter[T], cmp func(T, T) int) optional.Optional[tuple.Pair[T, T]]
- func MinMaxByKey[T any, K cmp.Ordered](iter Iter[T], keyFn func(T) K) optional.Optional[tuple.Pair[T, T]]
- func NoneOf[T any](iter Iter[T], predicate func(T) bool) bool
- func Nth[T any](iter Iter[T], n int) optional.Optional[T]
- func Partition[T any](iter Iter[T], partition func(T) bool) (Iter[T], Iter[T])
- func PositionLeft[T any](iter Iter[T], f func(T) bool) optional.Optional[int]
- func ReduceLeft[T any](iter Iter[T], f func(T, T) T) optional.Optional[T]
- func ReduceRight[T any](iter PrevIter[T], f func(T, T) T) optional.Optional[T]
- func ToString[T fmt.Stringer](iter Iter[T], sep string) string
- func ToStringBy[T any](iter Iter[T], sep string, f func(T) string) string
- func UnzipBy[A, B, C any](iter Iter[A], unzip func(A) (B, C)) (Iter[B], Iter[C])
- type AllOfIter
- type AnyOfIter
- type CmpByIter
- type CmpByKeyIter
- type CmpIter
- type CountByIter
- type CountIter
- type EnumerateIter
- type EqualByIter
- type EqualByKeyIter
- type EqualIter
- type Extend
- type FilterIter
- type FilterMapIter
- type FindLeftIter
- type FindMapIter
- type FindRightIter
- type FoldLeftIter
- type FoldRightIter
- type ForEachIter
- type IsSortedByIter
- type IsSortedByKeyIter
- type IsSortedIter
- type Iter
- func Chain[T any](iter Iter[T], other Iter[T]) Iter[T]
- func Counter() Iter[int]
- func Empty[T any]() Iter[T]
- func Enumerate[T any](iter Iter[T]) Iter[tuple.Pair[int, T]]
- func Filter[T any](iter Iter[T], f func(T) bool) Iter[T]
- func FilterMap[T, U any](iter Iter[T], f func(T) optional.Optional[U]) Iter[U]
- func Map[T, U any](iter Iter[T], f func(T) U) Iter[U]
- func MapWhile[T, U any](iter Iter[T], f func(T) optional.Optional[U]) Iter[U]
- func OfChan[T any](ch <-chan T) Iter[T]
- func Range(start int, end int) Iter[int]
- func Repeat[T any](v T) Iter[T]
- func Rev[T any](iter PrevIter[T]) Iter[T]
- func Skip[T any](iter Iter[T], n int) Iter[T]
- func StepBy[T any](iter Iter[T], step int) Iter[T]
- func Successor[T any](init T, successor func(T) optional.Optional[T]) Iter[T]
- func Take[T any](iter Iter[T], n int) Iter[T]
- func Zip[A, B any](iter Iter[A], other Iter[B]) Iter[tuple.Pair[A, B]]
- func ZipBy[A, B, C any](iter Iter[A], other Iter[B], f func(A, B) C) Iter[C]
- type IterFunc
- type Iterable
- type MapIter
- type MapWhileIter
- type MaxByIter
- type MaxByKeyIter
- type MaxIter
- type MinByIter
- type MinByKeyIter
- type MinIter
- type MinMaxByIter
- type MinMaxByKeyIter
- type MinMaxIter
- type NoneOfIter
- type PartitionIter
- type PositionLeftIter
- type PrevIter
- type PrevIterable
- type SkipIter
- type SkipWhileIter
- type StepByIter
- type TailIter
- type TakeIter
- type TakeWhileIter
- type ToStringByIter
- type ToStringIter
- type UnzipByIter
- type ZipByIter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllOf ¶
AllOf tests if every element of the iterator matches a predicate.
allOf() takes a closure that returns true or false. It applies this closure to each element of the iterator, and if they all return true, then so does allOf(). If any of them return false, it returns false.
allOf() is short-circuiting; in other words, 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.
Examples:
s := []int{1, 2, 3} assertTrue(iter.AllOf(slices.Iter(s)), func(x int) bool { return x < 10 }) assertFalse(iter.AllOf(slices.Iter(s)), func(x int) bool { return x > 100 })
func AnyOf ¶
AnyOf tests if any element of the iterator matches a predicate.
anyOf() takes a closure 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.
anyOf() is short-circuiting; in other words, 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.
Examples:
s := []int{1, 2, 3} assertTrue(iter.Any(slices.Iter(s)), func(x int) bool { return x%2 == 0 }) assertFalse(iter.Any(slices.Iter(s)), func(x int) bool { return x > 100 })
func CollectInto ¶
func CollectToSlice ¶
func EqualByKey ¶
func EqualByKey[T any, K comparable](iter Iter[T], other Iter[T], keyFn func(T) K) bool
func MinMaxByKey ¶
func NoneOf ¶
NoneOf tests if none element of the iterator matches a predicate.
noneOf() takes a closure that returns true or false. It applies this closure to each element of the iterator, and if none of them return true, then so does none(). If they all return false, it returns true.
An empty iterator returns true.
Examples:
s := []int{1, 2, 3} assertTrue(iter.None(slices.Iter(s)), func(x int) bool { return x%2 == 0 }) assertFalse(iter.None(slices.Iter(s)), func(x int) bool { return x > 100 })
func PositionLeft ¶
PositionLeft searches for an element in an iterator, returning its index.
PositionLeft() takes a closure that returns true or false. It applies this closure to each element of the iterator, and if one of them returns true, then PositionLeft() returns Some(index). If all of them return false, it returns None.
PositionLeft() is short-circuiting; in other words, it will stop processing as soon as it finds a true.
Types ¶
type CmpByKeyIter ¶
type CountByIter ¶
type EnumerateIter ¶
type EqualByIter ¶
type EqualByKeyIter ¶
type EqualByKeyIter[T any, K comparable] interface { Iter[T] EqualByKey(other Iter[T], keyFn func(T) K) bool }
type FilterMapIter ¶
type FindLeftIter ¶
type FindMapIter ¶
type FindRightIter ¶
type FoldLeftIter ¶
type FoldRightIter ¶
type ForEachIter ¶
type IsSortedByIter ¶
type IsSortedByKeyIter ¶
type Iter ¶
type Iter[T any] interface { // Next advances the iter and returns the next value. // // Returns [optional.None] when iteration is finished. // // Example: // iter := slices.Iter(1, 2, 3) // iter.Next() // Some(1) // iter.Next() // Some(2) // iter.Next() // Some(3) // iter.Next() // None Next() optional.Optional[T] }
Iter is the interface that wraps the basic methods for iterating over a collection.
💣 Important: Iterators usually contains state, so the behavior of reuse an Iter is undefined.
type MapWhileIter ¶
type MaxByKeyIter ¶
type MinByKeyIter ¶
type MinMaxByIter ¶
type MinMaxByKeyIter ¶
type MinMaxIter ¶
type PartitionIter ¶
type PositionLeftIter ¶
type PrevIter ¶
PrevIter is the interface that wraps the basic methods for iterating over a collection in both directions.
func OfSliceVariadic ¶
OfSliceVariadic create a new Iter[T] from variadic sequence of T