rxjava-migration
RxJava Migration
Migrate RxJava to Kotlin coroutines/flows incrementally. Only invoke this skill when the user explicitly asks to migrate RxJava code. Simple cases map directly; complex cases need a strategy and user input before any code is written.
Step 1: Complexity gate
Classify before writing any migrated code. A chain is Complex if ANY of: nested flatMap/switchMap with an inner Single/Observable; a custom Scheduler; complex error recovery (retryWhen, backoff, retry counts); multi-source zip/combineLatest (3+ sources); Flowable with an explicit backpressure strategy; a Subject shared across classes; or an unclear API return type. Any single Complex criterion makes the whole chain Complex — a two-operator chain with retryWhen is Complex.
Always confirm what each called API returns before migrating — do not assume. A leaf you think is migrated may still return Single/Observable.
Type mapping (state it explicitly — don't silently transform)
| RxJava | Coroutines/Flow |
|---|---|
Observable<T> / Flowable<T> |
Flow<T> (Flowable: match the original backpressure with buffer() / conflate()) |
Single<T> / Maybe<T> / Completable |
suspend fun: T / T? / Unit |
PublishSubject / ReplaySubject(n) |
MutableSharedFlow(replay = 0 / n) |
BehaviorSubject<T> |
ask — MutableStateFlow vs MutableSharedFlow(replay = 1) |