[−][src]Trait rxrust::ops::reduce::Reduce
The Reduce
operator applies a function to the first item emitted by the
source observable and then feeds the result of the function back into the
function along with the second item emitted by the source observable,
continuing this process until the source observable emits its final item
and completes, whereupon the observable returned from Reduce
emits the
final value returned from the function.
Provided methods
fn reduce_initial<InputItem, BinaryOp>(
self,
initial: OutputItem,
binary_op: BinaryOp
) -> ReduceOp<Self, BinaryOp, InputItem, OutputItem> where
Self: Sized,
BinaryOp: Fn(OutputItem, InputItem) -> OutputItem,
OutputItem: Clone,
self,
initial: OutputItem,
binary_op: BinaryOp
) -> ReduceOp<Self, BinaryOp, InputItem, OutputItem> where
Self: Sized,
BinaryOp: Fn(OutputItem, InputItem) -> OutputItem,
OutputItem: Clone,
Apply a function to each item emitted by an observable, sequentially, and emit the final value, after source observable completes.
Emits error when source observable emits it.
Arguments
initial
- An initial value to start the successive reduction from.binary_op
- A closure acting as a binary (folding) operator.
Examples
use rxrust::prelude::*; use rxrust::ops::Reduce; observable::from_iter(vec![1, 1, 1, 1, 1]) .reduce_initial(100, |acc, v| acc + v) .subscribe(|v| println!("{}", v)); // print log: // 105
fn reduce<InputItem, BinaryOp>(
self,
binary_op: BinaryOp
) -> LastOrOp<ScanOp<Self, BinaryOp, InputItem, OutputItem>, OutputItem> where
Self: Sized,
BinaryOp: Fn(OutputItem, InputItem) -> OutputItem,
OutputItem: Default + Clone,
self,
binary_op: BinaryOp
) -> LastOrOp<ScanOp<Self, BinaryOp, InputItem, OutputItem>, OutputItem> where
Self: Sized,
BinaryOp: Fn(OutputItem, InputItem) -> OutputItem,
OutputItem: Default + Clone,