Reduce

See also

  • Official ReactiveX documentation: Reduce
Observable.aggregate(accumulator, seed=None)

Applies an accumulator function over an observable sequence, returning the result of the aggregation as a single element in the result sequence. The specified seed value is used as the initial accumulator value.

For aggregation behavior with incremental intermediate results, see Observable.scan.

Example: 1 - res = source.reduce(lambda acc, x: acc + x) 2 - res = source.reduce(lambda acc, x: acc + x, 0)

Keyword arguments: :param types.FunctionType accumulator: An accumulator function to be

invoked on each element.
Parameters:seed (T) – Optional initial accumulator value.
Returns:An observable sequence containing a single element with the final accumulator value.
Return type:Observable
../../_images/aggregate.png
Observable.expand(selector, scheduler=None)

Expands an observable sequence by recursively invoking selector.

selector – {Function} Selector function to invoke for each produced
element, resulting in another sequence to which the selector will be invoked recursively again.
scheduler – {Scheduler} [Optional] Scheduler on which to perform the
expansion. If not provided, this defaults to the current thread scheduler.

Returns an observable {Observable} sequence containing all the elements produced by the recursive expansion.

../../_images/expand.png
Observable.reduce(accumulator, seed=None)

Applies an accumulator function over an observable sequence, returning the result of the aggregation as a single element in the result sequence. The specified seed value is used as the initial accumulator value.

For aggregation behavior with incremental intermediate results, see Observable.scan.

Example: 1 - res = source.reduce(lambda acc, x: acc + x) 2 - res = source.reduce(lambda acc, x: acc + x, 0)

Keyword arguments: :param types.FunctionType accumulator: An accumulator function to be

invoked on each element.
Parameters:seed (T) – Optional initial accumulator value.
Returns:An observable sequence containing a single element with the final accumulator value.
Return type:Observable
../../_images/reduce.png