I want to implement the following functions in the most re-active way. I need these for implementing the bijections for automatic conversion between the said types.
def convertScalaRXObservableToTwitterFuture[A](a: Observable[A]): TwitterFuture[A] = ???
def convertScalaRXObservableToTwitterFutureList[A](a: Observable[A]): TwitterFuture[List[A]] = ???
I came across this article on a related subject but I can't get it working.
Unfortunately the claim in that article is not correct and there can't be a true bijection between
Observableand anything likeFuture. The thing is thatObservableis more powerful abstraction that can represent things that can't be represented byFuture. For example,Observablemight actually represent an infinite sequence. For example seeObservable.interval. Obviously there is no way to represent something like this with aFuture. TheObservable.toListcall used in that article explicitly mentions that:and later it says:
Even if you limit yourself to only finite
Observables, stillFuturecan't fully express semantics ofObservable. ConsiderObservable.intervalRangethat generates a limited range one by one over some time period. WithObservablethe first event comes afterinitialDelayand then you get event eachperiod. WithFutureyou can get only one event and it must be only when the sequence is fully generated soObservableis completed. It means that by transformingObservable[A]intoFuture[List[A]]you immediately break the main benefit ofObservable- reactivity: you can't process events one by one, you have to process them all in a single bunch.To sum up the claim at the first paragraph of the article:
is false because conversion
Observable[A]->Future[List[A]]exactly looses the "event-driven nature" ofObservableand there is no way to work this around.P.S. Actually the fact that
Futureis less powerful thanObservableshould not be a big surprise. If it was not, why anybody would createObservablein the first place?