def sum_( key_mapper: Optional[Mapper[Any, float]] = None ) -> Callable[[Observable[Any]], Observable[float]]: if key_mapper: return compose(ops.map(key_mapper), ops.sum()) def accumulator(prev: float, cur: float) -> float: return prev + cur return ops.reduce(seed=0, accumulator=accumulator)
def count_( predicate: Optional[Predicate[_T]] = None, ) -> Callable[[Observable[_T]], Observable[int]]: if predicate: return compose( ops.filter(predicate), ops.count(), ) def reducer(n: int, _: _T) -> int: return n + 1 counter = ops.reduce(reducer, seed=0) return counter
def create(): return xs.pipe(ops.reduce(lambda acc, x: acc + x, 42))
def create(): return xs.pipe(ops.reduce(accumulator=lambda acc, x: acc + x))
def test_reduce_seed_none_does_not_crash(self): reactivex.empty().pipe(ops.reduce(lambda acc, v: v, seed=None)).subscribe()