Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package com.coderefer.rxandroidexamples.intro.operators.transform
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.coderefer.rxandroidexamples.R
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import java.util.concurrent.TimeUnit
private const val TAG = "FlatMapOperator"
class FlatMapOperatorActivity : AppCompatActivity() {
private val items: List<Int> = listOf(1,2,3,4,5)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_flat_map_operator)
Observable.fromIterable(items)
.flatMap {
Observable.just(it * 2)
.delay(it/10L, TimeUnit.SECONDS)
}
.doOnNext{
Log.d(TAG, it.toString())
}
.observeOn(Schedulers.io())
.subscribeOn(AndroidSchedulers.mainThread())
.subscribe()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.