1

If I have something like this:

scheduler = EventLoopScheduler()

obs1 = rx.range(0, 10)
obs2 = rx.range(20, 30).pipe(ops.combine_latest(obs1))

obs2.subscribe(lambda it: print(it), scheduler=scheduler)

time.sleep(5)

It gives me an output like:

(21, 0)
(21, 1)
(22, 1)
(22, 2)

How do I extend this for more than 2 observables though? For example, if I do this:

scheduler = EventLoopScheduler()

obs1 = rx.range(0, 10)
obs2 = rx.range(20, 30).pipe(ops.combine_latest(obs1))
obs3 = rx.range(40, 50).pipe(ops.combine_latest(obs2))

obs3.subscribe(lambda it: print(it), scheduler=scheduler)

time.sleep(5)

I get:

(41, (20, 0))
(41, (21, 0))
(42, (21, 0))
(42, (21, 1))
(42, (22, 1))
(43, (22, 1))
(43, (22, 2))
(43, (23, 2))

However, what I really want is the latest of 3 in a flat list like:

(41, 20, 0)
(41, 21, 0)
etc

How can I achieve this?

1 Answers1

1

Figured it out:

scheduler = EventLoopScheduler()

obs1 = rx.range(0, 10)
obs2 = rx.range(20, 30)
obs3 = rx.range(30, 40)

rx.combine_latest(obs1, obs2, obs3).subscribe(lambda it: print(it), scheduler=scheduler)

time.sleep(5)