Пример #1
0
    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
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())