I'm trying to get my head around the rxpy library for functional reactive programming (FRP) and I've already hit a roadblock. I'm writing a small program that expects data to be streamed in via standard input (sys.stdin).
My question is therefore simple: how can I create an rx.Observable instance that will asynchronously read from stdin? Are there built-in mechanisms to create Observable instances from streams?
I've never used
RxPy, but I have a bit of familiarity withRxJS.RxPyhas a number of built-in methods that you could likely use for this purpose, but I'm inclined to create an Observable factory. TakingObservableCreation.from_arrayas our guide, let's try that now. (Note: I haven't run this code, but it should get you most of the way there)Then just use it like this:
This will create an observable over each line of stdin until EOF. It's blocking, but there are ways around that. It can also be tuned with a different scheduler.