xoutil.fp.iterators – High-level functional tools for iterators

Functional tools for functions that returns iterators (generators, etc.)

Warning

This module is experimental. It may be removed completely, moved or otherwise changed.

xoutil.fp.iterators.kleisli_compose(*fs)[source]

The Kleisli composition operator.

For two functions, kleisli_compose(g, f) returns:

lambda x: (z for y in f(x) for z in g(y))

In general this is, reduce(_compose, fs, lambda x: [x]); where _compose is the lambda for two arguments.

Note

Despite name (Kleisli), Python does not have a true Monad type-class. So this function works with functions taking a single argument and returning an iterator – it also works with iterables.

New in version 1.9.6.

Changed in version 1.9.7: Name changed to kleisli_compose.

xoutil.fp.iterators.iter_compose()

Deprecated since version 1.9.7: Alias of xoutil.fp.iterators.kleisli_compose()