RxJava zipWith IDE error in Kotlin using Android Studio 3.0

I want to create an Observable that emits some elements and an Observable containing a list of objects with an Interval Observable, so that the elements from the first observable will emit with some time delay. Here is my implementation:

 val just1 = ArrayList<SomeClass1>()

fill in some elements

fun populateJust1() {
just1.add(SomeClass1("23", 23))
just1.add(SomeClass1("24", 24))
just1.add(SomeClass1("25", 25))
}

populateJust1()

and zip with interval Observable

Observable.fromIterable(just1)
            .zipWith(Observable.interval(2, TimeUnit.SECONDS)) { item: SomeClass1, interval: Long -> item }
            .subscribe(Consumer<SomeClass1> { someClass1 -> Log.v("someClass1", someClass1.toString()) })

However, the IDE, Android Studio 3.0 underlines the red zipWith statement and says:

. zipWith (((observer: Observer) → Unit)!, ((t1: SomeClass1, t2: Long) → R)!), R ; U = Long zipWith (: ((: ) → )!, : ((t1: SomeClass1, t2: U) → R)!): ! io.reactivex.Observable zipWith (ObservableSource!, BiFunction!), R ; U = ! zipWith (: ObservableSource!, : BiFunction!): ! io.reactivex.Observable zipWith ((Mutable) Iterable!, BiFunction!), U, R zipWith (: (Mutable) Iterable!, zipper: BiFunction!): ! io.reactivex.Observable zipWith ((Mutable) Iterable!, ((t1: SomeClass1, t2: Long) → R)!), R ; U = zipWith (: (Mutable) Iterable!, zipper: ((t1: SomeClass1, t2: U) → R)!): ! io.reactivex.Observable

? Java, .

+4
2

Kotlin zipWith lambda.

BiFunction :

data class SomeClass(val a: String, val b: Int)

val list = listOf(SomeClass("1", 1), SomeClass("2", 2))

Observable
        .fromIterable(list)
        .zipWith(Observable.interval(2, TimeUnit.SECONDS),
                BiFunction { item: SomeClass, _: Long -> item })
        .subscribe { Log.v("someClass", it.toString())
+2

RxKotlin, , . Single.zipWith:

fun <T, U> Single<T>.zipWith(other: SingleSource<U>): Single<Pair<T,U>>
    = zipWith(other, BiFunction { t, u -> Pair(t,u) })
+1

Source: https://habr.com/ru/post/1689481/


All Articles