Given a list of cars (List<Car> cars
), I can do:
Observable.just(cars); //returns an Observable that emits one List<Car> Observable.from(cars); //returns an Observable that emits a squence of Car
Is there a way I can go from an Observable
of a List<Car>
to a sequence of Observable<Car>
?
Something like a from
without parameters
Obserable.just(cars).from()
Unfortunately, there is no straightforward way to convert an Observable to Maybe (unless you are interested in just the firstElement ). You can convert it to Single first though and then to Maybe using toMaybe . This observable is only concerned about two things, if some action is executed or an error is encountered.
You cannot 'extract' something from an observable. You get items from observable when you subscribe to them (if they emit any). Since the object you are returning is of type Observable, you can apply operators to transform your data to your linking.
You can map an Observable<List<Car>>
to Observable<Car>
like so:
yourListObservable.flatMapIterable(x -> x)
Note that flatMapping might not preserve the order of the source observable. If the order matters to you, use concatMapIterable
. Read here for more details.
you can use this
flatMap { t -> Observable.fromIterable(t) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With