Python chunked — Split Iterable into Fixed-Size Pieces
Lazy chunker that works on any iterable, not just lists. Common building block for batch APIs — "send 50 rows per request" — without loading the source into memory.
Remove duplicates while preserving original order (set() loses order on collisions). Optional key function lets you dedupe by a derived value — e.g., lowercased email.
`rayon` lets you parallelize CPU-bound iterator chains by changing `.iter()` to `.par_iter()`. Handles thread-pool, work-stealing, and synchronization for you.
Iterate over an iterable with a rolling window of N items. itertools.batched (Python 3.12+) gives you NON-overlapping chunks; this helper gives overlapping ones, common for moving averages or n-gram analysis.
`fold` is the general aggregator: starts from an accumulator, applies a fn to each item. `reduce` uses the first item as the seed. `scan` yields intermediate accumulator values.
Take the first N items of an iterable (or while a predicate holds). drop is the complement. Lazy via islice + itertools.dropwhile — works on infinite generators.
A dict-returning groupby that doesn't require sorted input. Like itertools.groupby but materializes the groups so consumers can iterate them multiple times.
Rust iterators are lazy and zero-cost. Chain transformations and finally collect into a concrete container. The compiler unrolls the whole pipeline into a tight loop.
When you want to return a complex iterator chain or closure, you don't need to spell out the type. `impl Trait` lets the compiler infer the concrete type while exposing only the API contract.
Implementing `Iterator` is just supplying a `next() -> Option<Item>`. You automatically gain `map`, `filter`, `collect`, and every other adapter for free.
Go 1.23 added "range over func" — your own functions can produce values that work with `for v := range fn`. Cleaner than channels for in-process iteration without goroutine overhead.