ReactiveX / rxdart

The Reactive Extensions for Dart
http://reactivex.io
Apache License 2.0
3.36k stars 271 forks source link

Adding FlatMapLast #705

Closed pomarec closed 1 year ago

hoc081098 commented 1 year ago

I see it is the same as switchMap 🤔

pomarec commented 1 year ago

Yes i though so aswell but switch map keeps emiting from previous generated streams. In the first test it would emit ['a-1', 'b-1', 'a-2', 'b-2', emitsDone]

hoc081098 commented 1 year ago

@pomarec, switchMap cancels previous inner stream and start listening to new inner stream.

  await Stream.fromFutures([
      Future.delayed(Duration(milliseconds: 1000), () => 'a'),
      Future.delayed(Duration(milliseconds: 2000), () => 'b')
    ]).switchMap<void>((String value) => Stream.fromFutures([
        Future.delayed(Duration(milliseconds: 300), () => '$value 1 '),
        Future.delayed(Duration(milliseconds: 1500), () => '$value 2 '),
    ])).forEach(print);  // prints a1, b1, b2
pomarec commented 1 year ago

My bad, we got lost with my workmate. Thanks for your attention.