示例#1
0
文件: _sum.py 项目: lizh06/RxPY
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)
示例#2
0
文件: _count.py 项目: lizh06/RxPY
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
示例#3
0
 def create():
     return xs.pipe(ops.reduce(lambda acc, x: acc + x, 42))
示例#4
0
 def create():
     return xs.pipe(ops.reduce(accumulator=lambda acc, x: acc + x))
示例#5
0
 def test_reduce_seed_none_does_not_crash(self):
     reactivex.empty().pipe(ops.reduce(lambda acc, v: v,
                                       seed=None)).subscribe()