Skip to content

Pure Kotlin reactive operators library for educational purposes

License

Notifications You must be signed in to change notification settings

dvpermyakov/rx-kotlin

Repository files navigation

rx-kotlin operators

CircleCI Bintray License: MIT

  1. Creating
    • Create
    • Empty
    • FromCallable
    • FromList
    • Just
    • Never
    • Range
  2. Transforming
    • Buffer
    • ConcatMap
    • FlatMap
    • Map
    • SwitchMap
  3. Filtering
    • Distinct
    • Filter
    • TakeLast
  4. Combining
    • CombineLatest
    • Concat
    • Merge
    • Zip
  5. Utility
    • DoOnNext
    • DoOnSubscribe
    • ObserveOn
    • SubscrubeOn
  6. Subjects
    • AsyncSubject
    • BehaviorSubject
    • PublishSubject
    • ReplaySubject

Gradle:

repositories {
   jcenter()
}
dependencies {
   implementation 'com.dvpermyakov:rx-kotlin:0.1.2'
}

Example:

class TransactionInteractor {
    private val cardRepository = CardRepository()
    private val transactionRepository = TransactionRepository()

    fun getAllTransactions(): Observable<Transaction> {
        return Observable.concatList(
            listOf(
                cardRepository.getMyCards().subscribeOn(ThreadScheduler()),
                cardRepository.getOtherCards().subscribeOn(ThreadScheduler())
            )
        )
            .doOnNext { Log.e(TAG, "card = $it") }
            .switchMap { card ->
                transactionRepository.getTransactions(card)
                    .subscribeOn(ThreadScheduler())
                    .doOnNext { Log.e(TAG, "transaction = $it for card = ${card.id}") }
            }
    }

    companion object {
        private const val TAG = "TransactionInteractor"
    }
}