Closed rvanheest closed 8 years ago
It's not necessary to add an Option overload. It's already supported. See
scala> Observable.from(Some(1)).foreach(println)
1
Try is missing. So PR is welcome!
Agree kind of agree on the Option
, although it seems that you can't do Some(1).toObservable
with that. I think that is because the compiler has to do 2 implicit conversions for that: the Iterable[T]
to Option[T]
and the toObservable
conversion. So that's why I suggested to do the Option
part as well.
Regarding the Try
, I have made a similar thing as the ObservableExtensions
in the package object, so the syntax would be Try(...).toObservable
. But now that I'm thinking about it, maybe you would like to have the Observable.from(Try(...))
alternative as well... I'll add this last bit and do a PR. Then we'll see what we can use and what can be left out!
Closing, as this was solved in #210
Would it make any sense to have conversion methods from
scala.util.Try
andscala.Option
torx.lang.scala.Observable
? I mean, there is a conversion fromIterable
toObservable
inrx.lang.scala.ObservableExtensions
, which I view as the Scala equivalent of RxJava'sObservable.from
.Java does not really have type level notions of
Try
andOption
(the latter only in Java 8), so it makes sense that RxJava does not have them. Scala, however, does have these types and in my view they should have a similar conversion method asIterable
.The implementations would of course be very simple:
Option
Some(v)
->OnNext(v)
followed byOnCompleted
None
->OnCompleted
Try
Success(v)
->OnNext(v)
followed byOnCompleted
Failure(e)
->OnError(e)
LMKWYT! I'd be more than happy to do another PR!