Understand the difference between `it` and `itx` iterators
mainThe library provides two distinct packages for iterators:
itpackage: Uses standard library typesiter.Seqoriter.Seq2. These are functional but do not support method chaining.itxpackage: Uses custom typesitx.Iterator[V]oritx.Iterator2[V, W]. These allow for dot-chaining (e.g.,iter.Filter(...).Take(3).Collect()).
Critical Usage Warnings
- Infinite Iterators: Some iterators (like
Cycle,Repeat, orNaturalNumbers) yield infinite values. Avoid using functions likeslices.Collectdirectly on them without bounding the size (e.g., usingTake), otherwise, you will trigger an infinite loop. - Iterator Consumption: Many iterators take another iterator as an argument. Do not reuse an iterator after passing it to another function; doing so risks multiple functions attempting to consume a single, non-thread-safe iterator, leading to difficult-to-debug behavior.
// it package (non-chainable)
numbers := it.Chain(slices.Values([]int{1, 2}), slices.Values([]int{3, 4}))
// itx package (chainable)
numbers := itx.FromSlice([]int{1, 2}).Chain(slices.Values([]int{3, 4}))