npstreams.preduce

npstreams.preduce(func, iterable, args=None, kwargs=None, processes=1, ntotal=None)

Parallel application of the reduce function, with keyword arguments.

Parameters
  • func (callable) – Function to be applied to every element of iterable.

  • iterable (iterable) – Iterable of items to be reduced. Generators are consumed.

  • args (tuple or None, optional) – Positional arguments of function.

  • kwargs (dictionary or None, optional) – Keyword arguments of function.

  • processes (int or None, optional) – Number of processes to use. If None, maximal number of processes is used. Default is one.

  • ntotal (int or None, optional) – If the length of iterable is known, but passing iterable as a list would take too much memory, the total length ntotal can be specified. This allows for preduce to chunk better.

Returns

reduced

Return type

object

Notes

If processes is 1, preduce is equivalent to functools.reduce with the added benefit of using args and kwargs, but initializer is not supported.