Ejemplo n.º 1
0
 def _window_to_group(self, value):
     return value.pipe(
         ops.to_iterable(),
         ops.map(
             lambda x: rx.from_iterable(x).pipe(ops.group_by(
                 _group_by), ops.map(_group_to_batch), ops.merge_all())),
         ops.merge_all())
Ejemplo n.º 2
0
 def action1(scheduler, state):
     xs[0] = reactivex.from_iterable(
         ["alpha", "apple", "beta", "bat", "gamma"]
     ).pipe(
         ops.group_by(lambda s: s[0]),
         ops.map(lambda xs: xs.pipe(ops.to_iterable(), ops.map(list))),
         ops.merge_all(),
     )
Ejemplo n.º 3
0
 def subscription(scheduler, state):
     source = xs.pipe(
         ops.group_by(
             key_mapper=lambda x: x % 2,
             element_mapper=None,
             subject_mapper=lambda: reactivex.subject.ReplaySubject(2),
         )
     )
     return source.subscribe(observer_groups, scheduler=scheduler)
Ejemplo n.º 4
0
        def action1(scheduler, state):
            c["outer"] = xs.pipe(
                ops.group_by(
                    lambda x: x.lower().strip(),
                    lambda x: x[::-1],
                )
            )

            return c["outer"]
Ejemplo n.º 5
0
        def factory():
            def key_mapper(x):
                key_invoked[0] += 1
                return x.lower().strip()

            return xs.pipe(
                ops.group_by(key_mapper, lambda x: x),
                ops.map(lambda g: g.key),
            )
Ejemplo n.º 6
0
    def test_groupby_count(self):
        res = []
        counts = reactivex.from_(range(10)).pipe(
            ops.group_by(lambda i: "even" if i % 2 == 0 else "odd"),
            ops.flat_map(lambda i: i.pipe(
                ops.count(),
                ops.map(lambda ii: (i.key, ii)),
            )),
        )

        counts.subscribe(on_next=res.append)
        assert res == [("even", 5), ("odd", 5)]
Ejemplo n.º 7
0
        def factory():
            def key_mapper(x):
                key_invoked[0] += 1
                return x.lower().strip()

            def element_mapper(x):
                ele_invoked[0] += 1
                return x[::-1]  # Yes, this is reverse string in Python

            return xs.pipe(
                ops.group_by(key_mapper, element_mapper),
                ops.map(lambda g: g.key),
            )
Ejemplo n.º 8
0
        def factory():
            def key_mapper(x):
                key_invoked[0] += 1
                return x.lower().strip()

            def element_mapper(x):
                ele_invoked[0] += 1
                return x[::-1]

            return xs.pipe(
                ops.group_by(key_mapper, element_mapper),
                ops.map(lambda g: g.key),
            )