コード例 #1
0
ファイル: test_group_reduce.py プロジェクト: lizh06/RxPY
    def test_window_sum(self):
        res = []
        reactivex.from_(range(6)).pipe(
            ops.window_with_count(count=3, skip=1),
            ops.flat_map(lambda i: i.pipe(ops.sum(), )),
        ).subscribe(on_next=res.append)

        assert res == [3, 6, 9, 12, 9, 5, 0]
コード例 #2
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)
コード例 #3
0
 def create():
     return xs.pipe(ops.sum(lambda x: len(x)))
コード例 #4
0
 def create():
     return xs.pipe(ops.sum())