@@ -7,14 +7,14 @@ A library of iterators for use with `iter.Seq`. Requires Go 1.23+.
77``` go
88// The first 5 natural numbers
99numbers := slices.Collect (
10- it.Take (it.Count (), 5 ),
10+ it.Take (it.Count [ int ] (), 5 ),
1111)
1212
1313// All even numbers
14- evens := it.Filter (it.Count (), filter.IsEven )
14+ evens := it.Filter (it.Count [ int ] (), filter.IsEven )
1515
1616// String representations of integers
17- numbers := it.Map (it.Count (), strconv.Itoa )
17+ numbers := it.Map (it.Count [ int ] (), strconv.Itoa )
1818```
1919
2020_ [ Read the docs] ( https://pkg.go.dev/github.com/BooleanCat/go-functional/v2 ) _ to see the full iterator library.
@@ -24,3 +24,22 @@ _[Read the docs](https://pkg.go.dev/github.com/BooleanCat/go-functional/v2)_ to
2424``` terminal
2525go get github.com/BooleanCat/go-functional/v2@latest
2626```
27+
28+ ## Iterator Chaining
29+
30+ The iterators in this package were designed to be used with the native
31+ ` iter.Seq ` from Go's standard library. In order to facilitate complex
32+ sequences of iterators, the
33+ [ ` itx ` ] ( https://github.com/BooleanCat/go-functional/tree/main/it/itx ) package
34+ provides ` Iterator ` and ` Iterator2 ` as wrappers around ` iter.Seq ` and
35+ ` iter.Seq2 ` that allow for chaining operations.
36+
37+ Let's take a look at an example:
38+
39+ ``` go
40+ // The first 10 odd integers
41+ itx.Count [int ]().Filter (filter.IsOdd ).Take (10 ).Collect ()
42+ ```
43+
44+ Most iterators support chaining. A notable exception is ` it.Map ` which cannot
45+ support chaining due to limitations on Go's type system.
0 commit comments