Last active
April 21, 2019 10:04
-
-
Save vamsitallapudi/82684c8f3575e1219279537e4a43701a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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