def test_sequence_equal_not_equal_right_sym(self):
        scheduler = TestScheduler()
        msgs1 = [on_next(110, 1), on_next(190, 2), on_next(240, 3), on_next(290, 4), on_next(310, 5), on_next(340, 6), on_next(450, 7), on_completed(510)]
        msgs2 = [on_next(90, 1), on_next(270, 3), on_next(280, 4), on_next(300, 5), on_next(330, 6), on_next(340, 7), on_next(350, 8)]
        xs = scheduler.create_hot_observable(msgs1)
        ys = scheduler.create_hot_observable(msgs2)
        results = scheduler.start(lambda: ys.pipe(ops.sequence_equal(xs)))

        assert results.messages == [on_next(510, False), on_completed(510)]
        assert xs.subscriptions == [subscribe(200, 510)]
        assert ys.subscriptions == [subscribe(200, 510)]
    def test_sequence_equal_not_equal_2(self):
        scheduler = TestScheduler()
        msgs1 = [on_next(110, 1), on_next(190, 2), on_next(240, 3), on_next(290, 4), on_next(310, 5), on_next(340, 6), on_next(450, 7), on_next(490, 8), on_next(520, 9), on_next(580, 10), on_next(600, 11)]
        msgs2 = [on_next(90, 1), on_next(270, 3), on_next(280, 4), on_next(300, 5), on_next(330, 6), on_next(340, 7), on_next(350, 9), on_next(400, 9), on_next(410, 10), on_next(490, 11), on_next(550, 12), on_next(560, 13)]
        xs = scheduler.create_hot_observable(msgs1)
        ys = scheduler.create_hot_observable(msgs2)
        results = scheduler.start(create=lambda: xs.pipe(ops.sequence_equal(ys)))

        assert results.messages == [on_next(490, False), on_completed(490)]
        assert xs.subscriptions == [subscribe(200, 490)]
        assert ys.subscriptions == [subscribe(200, 490)]
    def test_sequence_equal_not_equal_4_sym(self):
        scheduler = TestScheduler()
        msgs1 = [on_next(250, 1), on_completed(300)]
        msgs2 = [on_next(290, 1), on_next(310, 2), on_completed(350)]
        xs = scheduler.create_hot_observable(msgs1)
        ys = scheduler.create_hot_observable(msgs2)
        results = scheduler.start(create=lambda: ys.pipe(ops.sequence_equal(xs)))

        assert results.messages == [on_next(310, False), on_completed(310)]
        assert xs.subscriptions == [subscribe(200, 300)]
        assert ys.subscriptions == [subscribe(200, 310)]
    def test_sequence_equal_not_equal_3(self):
        scheduler = TestScheduler()
        msgs1 = [on_next(110, 1), on_next(190, 2), on_next(240, 3), on_next(290, 4), on_next(310, 5), on_completed(330)]
        msgs2 = [on_next(90, 1), on_next(270, 3), on_next(400, 4), on_completed(420)]
        xs = scheduler.create_hot_observable(msgs1)
        ys = scheduler.create_hot_observable(msgs2)
        results = scheduler.start(create=lambda: xs.pipe(ops.sequence_equal(ys)))

        assert results.messages == [on_next(420, False), on_completed(420)]
        assert xs.subscriptions == [subscribe(200, 330)]
        assert ys.subscriptions == [subscribe(200, 420)]
示例#5
0
    def open(self):
        print("WebSocket aberto")

        # Um Sujeito é observável e observ5ador, portanto, podemos nos inscrever
        # para ele e também alimentá-lo (on_next) com novos valores
        self.subject = Subject()

        # Agora pegamos nossos óculos mágicos e projetamos o fluxo de bytes em
        query = self.subject.pipe(
            # 1. fluxo de códigos-chave
            ops.map(lambda obj: obj["keycode"]),
            # 2. fluxo de janelas (10 ints de comprimento)
            ops.window_with_count(10, 1),
            # 3. fluxo de booleanos, verdadeiro ou falso
            ops.flat_map(lambda win: win.pipe(ops.sequence_equal(codes))),
            # 4. fluxo de verdadeiras
            ops.filter(lambda equal: equal))
        # 4. então, assinamos o Trues e sinalizamos para a Konami! se virmos algum
        query.subscribe(lambda x: self.write_message("Konami!"))
示例#6
0
    def open(self):
        print("WebSocket opened")

        # A Subject is both an observable and observer, so we can both subscribe
        # to it and also feed (on_next) it with new values
        self.subject = Subject()

        # Now we take on our magic glasses and project the stream of bytes into
        # a ...
        query = self.subject.pipe(
            # 1. stream of keycodes
            ops.map(lambda obj: obj["keycode"]),
            # 2. stream of windows (10 ints long)
            ops.window_with_count(10, 1),
            # 3. stream of booleans, True or False
            ops.flat_map(lambda win: win.pipe(ops.sequence_equal(codes))),
            # 4. stream of Trues
            ops.filter(lambda equal: equal))
        # 4. we then subscribe to the Trues, and signal Konami! if we see any
        query.subscribe(lambda x: self.write_message("Konami!"))
示例#7
0
    def open(self):
        print("WebSocket opened")

        # A Subject is both an observable and observer, so we can both subscribe
        # to it and also feed (on_next) it with new values
        self.subject = Subject()

        # Now we take on our magic glasses and project the stream of bytes into
        # a ...
        query = self.subject.pipe(
            # 1. stream of keycodes
            ops.map(lambda obj: obj["keycode"]),
            # 2. stream of windows (10 ints long)
            ops.window_with_count(10, 1),
            # 3. stream of booleans, True or False
            ops.flat_map(lambda win: win.pipe(ops.sequence_equal(codes))),
            # 4. stream of Trues
            ops.filter(lambda equal: equal)
        )
        # 4. we then subscribe to the Trues, and signal Konami! if we see any
        query.subscribe(lambda x: self.write_message("Konami!"))
示例#8
0
import rx
import rx.operators as ops

numbers = rx.from_([1, 2, 3, 4])
compare = rx.from_([1, 2, 3, 4])

numbers.pipe(ops.sequence_equal(compare)).subscribe(
    on_next=lambda i: print("on_next {}".format(i)),
    on_error=lambda e: print("on_error: {}".format(e)),
    on_completed=lambda: print("on_completed"))
"""Error Handling"""
op.catch()
op.retry()

"""Utility"""
op.delay()
op.materialize()
op.time_interval()
op.timeout()
op.timestamp()

"""Conditional and Boolean"""
op.all()
op.contains()
op.default_if_empty()
op.sequence_equal()
op.skip_until()
op.skip_while()
op.take_until()
op.take_while()

"""Connectable"""
op.publish()
op.ref_count()
op.replay()

"""Combining"""
op.combine_latest()
op.merge()
op.start_with()
op.zip()
 def create():
     return xs.pipe(ops.sequence_equal([3, 4]))
 def create():
     return xs.pipe(ops.sequence_equal([3, 4, 5, 6, 7, 8]))
 def create():
     return xs.pipe(ops.sequence_equal([3, 4, 5, 6, 7], on_error_comparer(5, ex)))
 def create():
     def comparer(x, y):
         return x % 2 == y % 2
     return xs.pipe(ops.sequence_equal([3 - 2, 4, 5 + 9, 6 + 42, 7 - 6], comparer))
 def create():
     def comparer(a, b):
         raise Exception(ex)
     return ys.pipe(ops.sequence_equal(xs, comparer))