Saturday, 28 July 2018

Python: how to execute two "aggregate" functions (like sum) concurrently, feeding them from the same iterator

Imagine we have an iterator, say range(1, 1000).__iter__(). And we have two functions, each accepting an iterator as the only parameter, say sum() and max(). In SQL world we would call them aggregate functions.

Is there any way to obtain results of both without buffering the iterator output?

To do it, we would need to pause and resume aggregate function execution, in order to feed them both with the same values without storing them. Maybe is there a way to express it using async things without sleeps?



from Python: how to execute two "aggregate" functions (like sum) concurrently, feeding them from the same iterator

No comments:

Post a Comment