Module grscheller.fp.iterators

Library of iterator related functions.

Functions

def accumulate(iterable: Iterable[_T], f: Callable[[_S, _T], _S], initial: Optional[_S] = None) ‑> Iterator[_S]

Returns an iterator of accumulated values.

  • pure Python version of standard library's itertools.accumulate
  • function f does not default to addition (for typing flexibility)
  • begins accumulation with an optional starting value
def concat(*iterables: Iterable[_T]) ‑> Iterator[_T]

Sequentially concatenate multiple iterators into one.

  • pure Python version of standard library's itertools.chain
  • performant to chain
def exhaust(*iterables: Iterable[_T]) ‑> Iterator[_T]

Merge together multiple iterator streams until all are exhausted.

  • returns when last iterator is exhausted
def merge(*iterables: Iterable[_T], yield_partials: bool = False) ‑> Iterator[_T]

Merge multiple iterable streams until one is exhausted.

  • returns when first iterator is exhausted
  • if yield_partials is true, yield any unmatched yielded values from the other iterables
  • this prevents data lose if any of the iterables are iterators with external references