why isnt there a concatMap operator when there was one in 2020
faisalmushtaq007 opened this issue · comments
Faisal Mushtaq commented
Help needed.
RxDart - Using map and concatMap
But i checked there isnt any method like that.
Actually what my task is that i have multiple apis in an Iterable. I want to execute that sequentially and ones response is parameter to another api. Can you please help me here.
Frank Pepermans commented
AsyncExpand is what you want, since this is natively supported by Dart, it made no sense to create a concatMap synonym
Faisal Mushtaq commented
@frankpepermans Can you show an example of it, how to use for multiple apis. I've been stuck with this for long. please!
Petrus Nguyễn Thái Học commented
@faisalmushtaq007 hope it helps you
import 'package:rxdart/rxdart.dart';
import 'dart:async';
Stream<String> task(int i, String param) =>
Rx.fromCallable(() => 'index $i: time=${DateTime.now()} - param=$param\n')
.delay(const Duration(seconds: 1));
void main() async {
String acc = null;
await Stream.fromIterable([1, 2, 3, 4, 5])
.asyncExpand((i) =>
task(i, acc)
.doOnData((v) => acc = v)
)
.forEach(print);
}