6.10. itertools

itertools provides various utilities which simplify the composition of generators and collectors.

definedrain

A constant of type Collector.

inline->> ( generator collector... )
inlinecascade ( collector... )

two collectors: every time a is full, b collects a and a is reset when b ends, the remainder of a is collected

inlinecat ( coll )

treat input as a generator and forward its arguments individually

inlinecollect ( coll )

run collector until full and return the result

inlinedemux ( init-value f collector... )
inlineeach ( generator collector )

fold output from generator into collector

inlinefilter ( f coll )
inlineflatten ( coll )

collect variadic input as individual single items

inlinegate ( f a b )

if f is true, collect input in a, otherwise collect in b when both are full, output both until then, new input for full containers is discarded

inlineimap ( gen f )
inlineipair ( gen N )

generate one variadic argument from N generated arguments

inlinelimit ( f coll )
inlinemap ( f coll )
inlinemux ( collector... )

send input into multiple collectors which each fork the target collector

inlinereduce ( init f )
inlinetake ( n coll )

limit collector to output n items

sugar(--> ... )

Expands a processing chain into nested expressions so that each expression is passed as tailing argument to the following expression.

__ can be used as a placeholder token to position the previous expression.

example:

--> x
    f
    g
    h 2 __
    k

expands to:

k
    h 2
        g
            f x
spicecompose ( ... )
spicejoin ( ... )
spicespan ( ... )
spicezip ( ... )