Documentation
¶
Index ¶
- func Collect[T any](iter Iterator[T]) []T
- func Find[T any](iter Iterator[T], predicate func(v T) bool) option.Option[T]
- func Fold[T any, U any](iter Iterator[T], initial U, biop func(U, T) U) U
- func ForEach[T any](iter Iterator[T], callback func(T))
- func ToChannel[T any](iter Iterator[T]) chan T
- type ChainIter
- type ChannelIter
- type CountIter
- type CycleIter
- type DropIter
- type ExhaustedIter
- type FilterIter
- type FilterMapIter
- type Iterator
- type LiftHashMapIter
- func (iter *LiftHashMapIter[T, U]) Close()
- func (iter *LiftHashMapIter[T, U]) Collect() []Tuple[T, U]
- func (iter *LiftHashMapIter[T, U]) Drop(n uint) *DropIter[Tuple[T, U]]
- func (iter *LiftHashMapIter[T, U]) Next() option.Option[Tuple[T, U]]
- func (iter *LiftHashMapIter[T, U]) Take(n uint) *TakeIter[Tuple[T, U]]
- type LiftHashMapKeysIter
- type LiftHashMapValuesIter
- func (iter *LiftHashMapValuesIter[T, U]) Close()
- func (iter *LiftHashMapValuesIter[T, U]) Collect() []U
- func (iter *LiftHashMapValuesIter[T, U]) Drop(n uint) *DropIter[U]
- func (iter *LiftHashMapValuesIter[T, U]) Next() option.Option[U]
- func (iter *LiftHashMapValuesIter[T, U]) Take(n uint) *TakeIter[U]
- type LiftIter
- type LinesIter
- type MapIter
- type RepeatIter
- type TakeIter
- type Tuple
- type ZipIter
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Collect ¶
Collect consumes an Iterator and returns all remaining items within a slice. It does not protect against infinite Iterators.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
)
func main() {
fmt.Println(iter.Collect[int](iter.Count().Take(3)))
}
Output: [0 1 2]
Example (Method) ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
)
func main() {
fmt.Println(iter.Count().Take(3).Collect())
}
Output: [0 1 2]
func Find ¶ added in v0.10.0
Find the first occurrence of a value that satisfies the predicate and return that value. If no value satisfies the predicate, return `None`.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
)
func main() {
values := iter.Lift([]string{"foo", "bar", "baz"})
bar := iter.Find[string](values, func(v string) bool { return v == "bar" })
fmt.Println(bar)
}
Output: Some(bar)
func Fold ¶ added in v0.3.0
Fold consumes an Iterator and returns the final result of applying the accumulator function to each element. The accumulator function accepts two arguments - an accumulator and an element and returns a new accumulator. The initial value is the accumulator for the first call. Fold does not protect against infinite Iterators.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
"github.com/BooleanCat/go-functional/iter/ops"
)
func main() {
sum := iter.Fold[int](iter.Count().Take(4), 0, ops.Add[int])
fmt.Println(sum)
}
Output: 6
func ForEach ¶ added in v0.11.0
ForEach consumes an iterator and executes callback function on each item.
func ToChannel ¶ added in v0.6.0
ToChannel consumes an iterator and returns a channel that will receive all values from the provided iterator. The channel is closed once the iterator is exhausted.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
)
func main() {
for number := range iter.ToChannel[int](iter.Lift([]int{1, 2, 3})) {
fmt.Println(number)
}
}
Output: 1 2 3
Types ¶
type ChainIter ¶ added in v0.4.0
type ChainIter[T any] struct { // contains filtered or unexported fields }
ChainIter implements `Chain`. See `Chain`'s documentation.
func Chain ¶ added in v0.4.0
Chain instantiates a `ChainIter` that will yield all items in the provided iterators to exhaustion, from left to right.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
)
func main() {
fmt.Println(iter.Chain[int](iter.Lift([]int{1, 2}), iter.Lift([]int{3, 4}), iter.Lift([]int{0, 9})).Collect())
}
Output: [1 2 3 4 0 9]
func (*ChainIter[T]) Collect ¶ added in v0.12.0
func (iter *ChainIter[T]) Collect() []T
Collect is an alternative way of invoking Collect(iter)
type ChannelIter ¶ added in v0.6.0
type ChannelIter[T any] struct { // contains filtered or unexported fields }
ChannelIter implements `FromChannel`. See `FromChannel`'s documentation.
func FromChannel ¶ added in v0.6.0
func FromChannel[T any](ch chan T) *ChannelIter[T]
FromChannel instantiates a `ChannelIter` that will yield each value from the provided channel.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
)
func main() {
ch := make(chan int, 2)
go func() {
ch <- 1
ch <- 2
close(ch)
}()
fmt.Println(iter.FromChannel(ch).Collect())
}
Output: [1 2]
func (*ChannelIter[T]) Collect ¶ added in v0.12.0
func (iter *ChannelIter[T]) Collect() []T
Collect is an alternative way of invoking Collect(iter)
func (*ChannelIter[T]) Drop ¶ added in v0.13.0
func (iter *ChannelIter[T]) Drop(n uint) *DropIter[T]
Drop is an alternative way of invoking Drop(iter)
func (*ChannelIter[T]) Next ¶ added in v0.6.0
func (iter *ChannelIter[T]) Next() option.Option[T]
Next implements the Iterator interface for `ChannelIter`.
func (*ChannelIter[T]) Take ¶ added in v0.13.0
func (iter *ChannelIter[T]) Take(n uint) *TakeIter[T]
Take is an alternative way of invoking Take(iter)
type CountIter ¶
type CountIter struct {
// contains filtered or unexported fields
}
CountIter implements `Count`. See `Count`'s documentation.
func Count ¶
func Count() *CountIter
Count instantiates a `CountIter` that will iterate over 0 and the natural numbers. Count is functionally "unlimited" although it does not protect against the integer limit.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
)
func main() {
counter := iter.Count()
fmt.Println(counter.Next())
fmt.Println(counter.Next())
fmt.Println(counter.Next())
}
Output: Some(0) Some(1) Some(2)
type CycleIter ¶ added in v0.12.0
type CycleIter[T any] struct { // contains filtered or unexported fields }
CycleIter implements `Cycle`. See `Cycle`'s documentation.
func Cycle ¶ added in v0.12.0
Cycle instantiates a `CycleIter` yielding all items from the provided iterator until exhaustion, and then yields them all over again on repeat.
Note that CycleIter stores the members from the underlying iterator so will grow in size as items are yielded until the underlying iterator is exhausted.
In most cases this iterator is infinite, except when the underlying iterator is exhausted before the first call to Next() in which case this iterator will always yield None.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
)
func main() {
numbers := iter.Cycle[int](iter.Lift([]int{1, 2})).Take(5)
fmt.Println(numbers.Collect())
}
Output: [1 2 1 2 1]
type DropIter ¶
type DropIter[T any] struct { // contains filtered or unexported fields }
DropIter implements `Drop`. See `Drop`'s documentation.
func Drop ¶
Drop instantiates a `DropIter` that will skip the number of items of its wrapped iterator by the provided count.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
)
func main() {
counter := iter.Drop[int](iter.Count(), 2)
fmt.Println(counter.Next().Unwrap())
}
Output: 2
Example (Method) ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
)
func main() {
counter := iter.Count().Drop(2)
fmt.Println(counter.Next().Unwrap())
}
Output: 2
func (*DropIter[T]) Collect ¶ added in v0.12.0
func (iter *DropIter[T]) Collect() []T
Collect is an alternative way of invoking Collect(iter)
type ExhaustedIter ¶
type ExhaustedIter[T any] struct{}
ExhaustedIter implements `Exhausted`. See `Exhausted`'s documentation.
func Exhausted ¶
func Exhausted[T any]() *ExhaustedIter[T]
Exhausted instantiates an `ExhaustedIter` that will immediately be exhausted (`Next` will always return a `None` variant).
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
)
func main() {
fmt.Println(iter.Exhausted[int]().Next())
}
Output: None
func (*ExhaustedIter[T]) Collect ¶ added in v0.12.0
func (iter *ExhaustedIter[T]) Collect() []T
Collect is an alternative way of invoking Collect(iter)
func (*ExhaustedIter[T]) Drop ¶ added in v0.13.0
func (iter *ExhaustedIter[T]) Drop(n uint) *DropIter[T]
Drop is an alternative way of invoking Drop(iter)
func (*ExhaustedIter[T]) Next ¶
func (iter *ExhaustedIter[T]) Next() option.Option[T]
Next implements the Iterator interface for `ExhaustedIter`.
func (*ExhaustedIter[T]) Take ¶ added in v0.13.0
func (iter *ExhaustedIter[T]) Take(n uint) *TakeIter[T]
Take is an alternative way of invoking Take(iter)
type FilterIter ¶
type FilterIter[T any] struct { // contains filtered or unexported fields }
FilterIter implements `Filter`. See `Filter`'s documentation.
func Exclude ¶
func Exclude[T any](iter Iterator[T], fun func(T) bool) *FilterIter[T]
Exclude instantiates a `FilterIter` that selectively yields only results that cause the provided function to return `false`.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
"github.com/BooleanCat/go-functional/iter/filters"
)
func main() {
filtered := iter.Exclude[int](iter.Lift([]int{0, 1, 0, 2}), filters.IsZero[int])
fmt.Println(filtered.Next())
fmt.Println(filtered.Next())
fmt.Println(filtered.Next())
}
Output: Some(1) Some(2) None
func Filter ¶
func Filter[T any](iter Iterator[T], fun func(T) bool) *FilterIter[T]
Filter instantiates a `FilterIter` that selectively yields only results that cause the provided function to return `true`.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
"github.com/BooleanCat/go-functional/iter/filters"
)
func main() {
filtered := iter.Filter[int](iter.Lift([]int{0, 1, 0, 2}), filters.IsZero[int])
fmt.Println(filtered.Next())
fmt.Println(filtered.Next())
fmt.Println(filtered.Next())
}
Output: Some(0) Some(0) None
func (*FilterIter[T]) Collect ¶ added in v0.12.0
func (iter *FilterIter[T]) Collect() []T
Collect is an alternative way of invoking Collect(iter)
func (*FilterIter[T]) Drop ¶ added in v0.13.0
func (iter *FilterIter[T]) Drop(n uint) *DropIter[T]
Drop is an alternative way of invoking Drop(iter)
func (*FilterIter[T]) Next ¶
func (iter *FilterIter[T]) Next() option.Option[T]
Next implements the Iterator interface for `Filter`.
func (*FilterIter[T]) Take ¶ added in v0.13.0
func (iter *FilterIter[T]) Take(n uint) *TakeIter[T]
Take is an alternative way of invoking Take(iter)
type FilterMapIter ¶ added in v0.7.0
FilterMapIter implements `FilterMap`. See `FilterMap`'s documentation.
func FilterMap ¶ added in v0.7.0
Accepts an underlying iterator as data source and a filtering + mapping function it allows the user to filter elements by returning a None variant and to transform elements by returning a Some variant.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
"github.com/BooleanCat/go-functional/option"
)
func main() {
selectAndTripleOdds := func(x int) option.Option[int] {
if x%2 == 0 {
return option.None[int]()
}
return option.Some(x * 3)
}
triples := iter.FilterMap[int](
iter.Count().Take(6),
selectAndTripleOdds,
)
fmt.Println(triples.Collect())
}
Output: [3 9 15]
func (*FilterMapIter[T, U]) Collect ¶ added in v0.12.0
func (iter *FilterMapIter[T, U]) Collect() []U
Collect is an alternative way of invoking Collect(iter)
func (*FilterMapIter[T, U]) Drop ¶ added in v0.13.0
func (iter *FilterMapIter[T, U]) Drop(n uint) *DropIter[U]
Drop is an alternative way of invoking Drop(iter)
func (*FilterMapIter[T, U]) Next ¶ added in v0.7.0
func (iter *FilterMapIter[T, U]) Next() option.Option[U]
Next implements the Iterator interface for `FilterMapIter`.
func (*FilterMapIter[T, U]) Take ¶ added in v0.13.0
func (iter *FilterMapIter[T, U]) Take(n uint) *TakeIter[U]
Take is an alternative way of invoking Take(iter)
type Iterator ¶
Iterator declares that each Iterator must implement a Next method. Successive calls to the next method shall return the next item in the Iterator, wrapped in an `Option.Some` variant.
Exhausted Iterators shall return a `None` variant of `Option` on every subsequent call.
type LiftHashMapIter ¶ added in v0.8.0
type LiftHashMapIter[T comparable, U any] struct { // contains filtered or unexported fields }
LiftHashMapIter implements `LiftHashMap`. See `LiftHashMap`'s documentation.
func LiftHashMap ¶ added in v0.8.0
func LiftHashMap[T comparable, U any](hashmap map[T]U) *LiftHashMapIter[T, U]
LiftHashMap instantiates a `LiftHashMapIter` that will yield all items in the provided map in the form iter.Tuple[key, value].
Unlike most iterators, `LiftHashMap` should be closed after usage (because range order is non-deterministic and the iterator needs to preserve its progress). This restriction may be removed if/when Go has a "yield" keyword.
The iterator is closed when any of the two conditions are met.
1. The caller explicitly invokes the `Close` method. 2. The iterator is exhausted.
It is safe to call Close multiple times or after exhaustion. It is not necessary to call Close if exhaustion is guaranteed, but may be wise to redundantly call Close if you're unsure.
func (*LiftHashMapIter[T, U]) Close ¶ added in v0.8.0
func (iter *LiftHashMapIter[T, U]) Close()
Close the iterator. See `LiftHashMap` documentation for details.
func (*LiftHashMapIter[T, U]) Collect ¶ added in v0.12.0
func (iter *LiftHashMapIter[T, U]) Collect() []Tuple[T, U]
Collect is an alternative way of invoking Collect(iter)
func (*LiftHashMapIter[T, U]) Drop ¶ added in v0.13.0
func (iter *LiftHashMapIter[T, U]) Drop(n uint) *DropIter[Tuple[T, U]]
Drop is an alternative way of invoking Drop(iter)
type LiftHashMapKeysIter ¶ added in v0.8.0
type LiftHashMapKeysIter[T comparable, U any] struct { // contains filtered or unexported fields }
LiftHashMapKeysIter implements `LiftHashMapKeys`. See `LiftHashMapKeys`' documentation.
func LiftHashMapKeys ¶ added in v0.8.0
func LiftHashMapKeys[T comparable, U any](hashmap map[T]U) *LiftHashMapKeysIter[T, U]
LiftHashMapKeys instantiates a `LiftHashMapKeysIter` that will yield all keys in the provided map.
See documentation on `LiftHashMap` for information on closing this iterator.
func (*LiftHashMapKeysIter[T, U]) Close ¶ added in v0.8.0
func (iter *LiftHashMapKeysIter[T, U]) Close()
Close the iterator. See `LiftHashMapKeys` documentation for details.
func (*LiftHashMapKeysIter[T, U]) Collect ¶ added in v0.12.0
func (iter *LiftHashMapKeysIter[T, U]) Collect() []T
Collect is an alternative way of invoking Collect(iter)
func (*LiftHashMapKeysIter[T, U]) Drop ¶ added in v0.13.0
func (iter *LiftHashMapKeysIter[T, U]) Drop(n uint) *DropIter[T]
Drop is an alternative way of invoking Drop(iter)
func (*LiftHashMapKeysIter[T, U]) Next ¶ added in v0.8.0
func (iter *LiftHashMapKeysIter[T, U]) Next() option.Option[T]
Next implements the Iterator interface for `LiftHashMapKeys`.
func (*LiftHashMapKeysIter[T, U]) Take ¶ added in v0.13.0
func (iter *LiftHashMapKeysIter[T, U]) Take(n uint) *TakeIter[T]
Take is an alternative way of invoking Take(iter)
type LiftHashMapValuesIter ¶ added in v0.8.0
type LiftHashMapValuesIter[T comparable, U any] struct { // contains filtered or unexported fields }
LiftHashMapValuesIter implements `LiftHashMapValues`. See `LiftHashMapValues`' documentation.
func LiftHashMapValues ¶ added in v0.8.0
func LiftHashMapValues[T comparable, U any](hashmap map[T]U) *LiftHashMapValuesIter[T, U]
LiftHashMapValues instantiates a `LiftHashMapValuesIter` that will yield all values in the provided map.
See documentation on `LiftHashMap` for information on closing this iterator.
func (*LiftHashMapValuesIter[T, U]) Close ¶ added in v0.8.0
func (iter *LiftHashMapValuesIter[T, U]) Close()
Close the iterator. See `LiftHashMapKeys` documentation for details.
func (*LiftHashMapValuesIter[T, U]) Collect ¶ added in v0.12.0
func (iter *LiftHashMapValuesIter[T, U]) Collect() []U
Collect is an alternative way of invoking Collect(iter)
func (*LiftHashMapValuesIter[T, U]) Drop ¶ added in v0.13.0
func (iter *LiftHashMapValuesIter[T, U]) Drop(n uint) *DropIter[U]
Drop is an alternative way of invoking Drop(iter)
func (*LiftHashMapValuesIter[T, U]) Next ¶ added in v0.8.0
func (iter *LiftHashMapValuesIter[T, U]) Next() option.Option[U]
Next implements the Iterator interface for `LiftHashMapValuesIter`.
func (*LiftHashMapValuesIter[T, U]) Take ¶ added in v0.13.0
func (iter *LiftHashMapValuesIter[T, U]) Take(n uint) *TakeIter[U]
Take is an alternative way of invoking Take(iter)
type LiftIter ¶
type LiftIter[T any] struct { // contains filtered or unexported fields }
LiftIter implements `Lift`. See `Lift`'s documentation.
func Lift ¶
Lift instantiates a `LiftIter` that will yield all items in the provided slice.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
"github.com/BooleanCat/go-functional/iter/filters"
)
func main() {
positives := iter.Filter[int](iter.Lift([]int{-1, 4, 6, 4, -5}), filters.GreaterThan(-1))
fmt.Println(positives.Collect())
}
Output: [4 6 4]
func (*LiftIter[T]) Collect ¶ added in v0.12.0
func (iter *LiftIter[T]) Collect() []T
Collect is an alternative way of invoking Collect(iter)
type LinesIter ¶
type LinesIter struct {
// contains filtered or unexported fields
}
LinesIter implements `Lines`. See `Lines`' documentation.
func Lines ¶
Lines instantiates a `LinesIter` that will yield each line from the provided `io.Reader`.
Be aware that since `Read` operations can fail, the result time of each item is `result.Result[[]byte]`. Errors will need to be handled as a failure is wrapped in an Ok variant. Multiple calls to `Next()` may simply repeat the same error and cause an infinite loop when collected.
Example ¶
package main
import (
"bytes"
"fmt"
"github.com/BooleanCat/go-functional/iter"
"github.com/BooleanCat/go-functional/iter/ops"
"github.com/BooleanCat/go-functional/result"
)
func main() {
lines := iter.Lines(bytes.NewBufferString("hello\nthere"))
unwrapped := iter.Map[result.Result[[]byte]](lines, ops.UnwrapResult[[]byte])
fmt.Println(unwrapped.Collect())
}
Output: [[104 101 108 108 111] [116 104 101 114 101]]
func (*LinesIter) Collect ¶ added in v0.12.0
Collect is an alternative way of invoking Collect(iter)
type MapIter ¶
type MapIter[T, U any] struct { // contains filtered or unexported fields }
MapIter implements `Map`. See `Map`'s documentation.
func LinesString ¶
LinesString instantiates a `LinesIter` with results converted to a string via a MapIter. See `Lines` documentation for more information.
Example ¶
package main
import (
"bytes"
"fmt"
"github.com/BooleanCat/go-functional/iter"
"github.com/BooleanCat/go-functional/iter/ops"
"github.com/BooleanCat/go-functional/result"
)
func main() {
lines := iter.LinesString(bytes.NewBufferString("hello\nthere"))
unwrapped := iter.Map[result.Result[string]](lines, ops.UnwrapResult[string])
fmt.Println(unwrapped.Collect())
}
Output: [hello there]
func Map ¶
Take instantiates a `MapIter` that will apply the provided function to each item yielded by the provided Iterator.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
)
func main() {
double := func(a int) int { return a * 2 }
items := iter.Map[int](iter.Lift([]int{0, 1, 2, 3}), double).Collect()
fmt.Println(items)
}
Output: [0 2 4 6]
func (*MapIter[T, U]) Collect ¶ added in v0.12.0
func (iter *MapIter[T, U]) Collect() []U
Collect is an alternative way of invoking Collect(iter)
type RepeatIter ¶ added in v0.12.0
type RepeatIter[T any] struct { // contains filtered or unexported fields }
RepeatIter implements `Repeat`. See `Repeat`'s documentation.
func Repeat ¶ added in v0.12.0
func Repeat[T any](item T) *RepeatIter[T]
Repeat instantiates a `RepeatIter` always yield the provided item.
This iterator will never be exhausted.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
)
func main() {
iter := iter.Repeat[int](42)
fmt.Println(iter.Next())
fmt.Println(iter.Next())
}
Output: Some(42) Some(42)
func (*RepeatIter[T]) Drop ¶ added in v0.13.0
func (iter *RepeatIter[T]) Drop(n uint) *DropIter[T]
Drop is an alternative way of invoking Drop(iter)
func (*RepeatIter[T]) Next ¶ added in v0.12.0
func (iter *RepeatIter[T]) Next() option.Option[T]
Next implements the Iterator interface for `RepeatIter`.
func (*RepeatIter[T]) Take ¶ added in v0.13.0
func (iter *RepeatIter[T]) Take(n uint) *TakeIter[T]
Take is an alternative way of invoking Take(iter)
type TakeIter ¶
type TakeIter[T any] struct { // contains filtered or unexported fields }
TakeIter implements `Take`. See `Take`'s documentation.
func Take ¶
Take instantiates a `TakeIter` that will limit the number of items of its wrapped iterator to a maximum limit.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
)
func main() {
iter := iter.Take[int](iter.Count(), 2)
fmt.Println(iter.Next())
fmt.Println(iter.Next())
fmt.Println(iter.Next())
}
Output: Some(0) Some(1) None
Example (Method) ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
)
func main() {
iter := iter.Count().Take(2)
fmt.Println(iter.Next())
fmt.Println(iter.Next())
fmt.Println(iter.Next())
}
Output: Some(0) Some(1) None
func (*TakeIter[T]) Collect ¶ added in v0.12.0
func (iter *TakeIter[T]) Collect() []T
Collect is an alternative way of invoking Collect(iter)
type ZipIter ¶
type ZipIter[T, U any] struct { // contains filtered or unexported fields }
ZipIter implements `Zip`. See `Zip`'s documentation.
func Zip ¶
Zip instantiates a `Zip` yield `Tuples` containing the result of a call to each provided Iterator's `Next`. The Iterator is exhausted when one of the provided Iterators is exhausted.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
)
func main() {
isEven := func(a int) bool { return a%2 == 0 }
evens := iter.Filter[int](iter.Count(), isEven)
odds := iter.Exclude[int](iter.Count(), isEven)
fmt.Println(iter.Zip[int, int](evens, odds).Take(3).Collect())
}
Output: [{0 1} {2 3} {4 5}]
func (*ZipIter[T, U]) Collect ¶ added in v0.12.0
Collect is an alternative way of invoking Collect(iter)