skip to content

Stream Operators

RxDart adds operators Dart's Stream lacks: switchMap to drop stale requests, debounceTime and throttleTime for input, combineLatest and zip to join sources. Interviewers ask for a search stream.

on this pageshow

explore

questions

5

In RxDart, how do switchMap, exhaustMap and flatMap differ, and which fits a search box, a submit button and parallel poster downloads?

level: middleimportance: must knowfreq 50%

basics

~20 s

switchMap cancels the running inner stream when a new event arrives, exhaustMap ignores new events until the running one completes, and flatMap runs them all concurrently, optionally capped by maxConcurrent. Search wants switchMap, a submit button exhaustMap, parallel downloads flatMap.

open as a page

In a Flutter app, when do Dart's core Stream methods suffice, and which RxDart operators have no core Stream equivalent?

level: juniorimportance: should knowfreq 36%

basics

~20 s

Core Stream already maps, filters, de-duplicates and runs async work in order (map, where, distinct, asyncMap, asyncExpand). RxDart earns its dependency for timing (debounceTime, throttleTime), cancel-or-ignore flattening (switchMap, exhaustMap, flatMap) and combining sources (combineLatest2, zip2, merge, withLatestFrom).

open as a page

In RxDart, what do throttleTime's leading and trailing defaults do, and why would a throttled movie search miss the final query?

level: middleimportance: should knowfreq 34%

basics

~20 s

throttleTime defaults to leading: true and trailing: false: it emits the first event, then drops everything else for the duration. Typing "dune" quickly searches for "d" and never for "dune"; search needs debounceTime or trailing: true.

open as a page

On a Flutter movie search screen, Rx.combineLatest2 of the query stream and a genre-filter stream shows nothing until a genre is tapped — why, and how do you fix it?

level: seniorimportance: should knowfreq 38%

basics

~20 s

Rx.combineLatest2 emits only after both sources have emitted at least once, and the genre stream emits only on a tap. Give it a starting value with startWith (or a seeded source), then switchMap the combined query and genre to the search call.

open as a page