1

How do I recover elements from an Observable sequence in RxPy

obs = Observable.from_([1,2,3])
print obs.first()

should print 1, but it returns another AnonymousObservable, instead of the element.

In general, what is the best operator to recover elements from an Observable sequence?

rook
  • 5,880
  • 4
  • 39
  • 51
Jaewan Kim
  • 45
  • 5

1 Answers1

1

This works for me

obs = Observable.from_([1,2,3])
first = list(obs.first().to_blocking())[0]
print(first)

The to_blocking call converts the sequence into an iterator (of type rx.core.blockingobservable.BlockingObservable), and the list() conversion allows to access the inner values.

mkzqeyns
  • 71
  • 2
  • 1
    Welcome to answering on SO, it might be helpful to outline _why_ your solution works and the original posters code does not, i.e. why are you calling to_blocking and why are you calling list() etc. – tolanj Oct 17 '16 at 14:03