RxJava2
kotlin
This works ok and I can concat 2 observables
Observable.concat(countries(), animals())
.subscribeBy {
println(it)
}
This the sample I can't understand as it use a lambda that seems to take a ObservableSource and I want to concat the 2 observables, but it results in a null exception. Just wondering what I am doing wrong with this. And what is the purpose to use a lambda with the concat?
Observable.concat<String> {
it.onNext(countries())
it.onNext(animals())
}.subscribeBy {
println(it)
}
private fun animals(): Observable<String> =
Observable.just("fox", "cat", "dog", "bear", "bat", "hare", "lion", "tiger")
private fun countries(): Observable<String> =
Observable.just("England", "France", "Thailand", "America", "Scotland", "Ice Land")
This is the crash I am getting:
Exception in thread "main" java.lang.NullPointerException
at io.reactivex.internal.operators.observable.ObservableConcatMap$SourceObserver.onNext(ObservableConcatMap.java:129)
This is the interface for the ObservableSource I think I am referring to.
public interface ObservableSource<T> {
void subscribe(@NonNull Observer<? super T> observer);
}
Many thanks for any suggestions