asyncExpandRecursive method

Stream<T> asyncExpandRecursive(
  1. Stream<T> mapper(
    1. StreamElement<T>
    )
)

Implementation

Stream<T> asyncExpandRecursive(Stream<T> Function(StreamElement<T>) mapper) {
  StreamController<T?> controller = StreamController();
  int counter = 0;
  final stream = controller.stream.doOnData((e) {
    final mapped = mapper(StreamElement(e, counter++));
    mapped.forEach(controller.add).catchError(controller.addError);
  });
  controller.add(null);
  this.forEach(controller.add);

  return stream.skip(1).cast<T>();
}