transducers package

Submodules

transducers.transducers module

class transducers.transducers.Missing[source]

Bases: object

Only for ‘is’ comparison to simplify arity testing. This is because None is a legal argument differing from ‘Not supplied.’

class transducers.transducers.Reduced(val)[source]

Bases: object

Only for ‘isinstance’ comparison to signal early termination of reduce.

transducers.transducers.append(r=<class 'transducers.transducers.Missing'>, x=<class 'transducers.transducers.Missing'>)[source]

Appender used by into. Will work with lists, deques, or anything with an appender.

transducers.transducers.cat(step)[source]

Cat transducers (will cat items from nested lists, e.g.).

transducers.transducers.compose(*fns)[source]

Compose functions using reduce on splat.

compose(f, g) reads ‘f composed with g’, or f(g(x))

Note: order of inner function application with transducers is inverted from the composition of the transducers.

transducers.transducers.dedupe(step)[source]

Removes duplicatees that occur in order. Accepts first inputs through and drops subsequent duplicates.

transducers.transducers.drop(n)[source]

Drops n items from beginning of input sequence.

transducers.transducers.drop_while(pred)[source]

Drops values so long as a condition is true.

transducers.transducers.eduction(xf, coll)[source]

Return a generator with transform applied. Not implemented.

transducers.transducers.ensure_reduced(x)[source]
transducers.transducers.filter(pred)[source]

Transducer version of filter.

transducers.transducers.into(target, xducer, coll)[source]

Transduces items from coll into target. :TODO: Write improved dispatch for collections?

transducers.transducers.keep(pred)[source]

Keep pred items for which pred does not return None.

transducers.transducers.keep_indexed(f)[source]

Keep values where f does not return None. f for keep indexed is a function that takes both index and value as inputs.

transducers.transducers.map(f)[source]

Transducer version of map, returns f(item) with each reduction step.

transducers.transducers.mapcat(f)[source]

Mapcat transducer - maps to a collection then cats item into one less level of nesting.

transducers.transducers.partition_all(n)[source]

Splits inputs into lists of size n.

transducers.transducers.partition_by(pred)[source]

Split inputs into lists by starting a new list each time the predicate passed in evaluates to a different condition (true/false) than what holds for the present list.

transducers.transducers.random() → x in the interval [0, 1).
transducers.transducers.random_sample(prob)[source]

Has prob probability of returning each input it receives.

transducers.transducers.reduce(function, iterable, initializer=<class 'transducers.transducers.Missing'>)[source]

For loop impl of reduce in Python that honors sentinal wrapper Reduced and uses it to signal early termination.

transducers.transducers.remove(pred)[source]

Remove anything that satisfies pred.

transducers.transducers.replace(smap)[source]

Replaces keys in smap with corresponding values.

transducers.transducers.take(n)[source]

Takes n values from a collection.

transducers.transducers.take_nth(n)[source]

Takes every nth item from input values.

transducers.transducers.take_while(pred)[source]

Takes while a condition is true. Note that take_while will take the first input that tests false, so be mindful of mutable input sources.

transducers.transducers.transduce(xform, f, start, coll=<class 'transducers.transducers.Missing'>)[source]

Return the results of calling transduce on the reducing function, can compose transducers using compose defined above.

transducers.transducers.unreduced(x)[source]

Module contents

transducers.random() → x in the interval [0, 1).

Table Of Contents

Previous topic

Welcome to transducers documentation!

This Page