Yield* in dart

import 'dart:async';

main(List args) async {
  await for (int i in numbersDownFrom(10)) {
    print('$i apples');
  }
}

Stream numbersDownFrom(int n) async* {
  if (n >= 0) {
    await new Future.delayed(new Duration(milliseconds: 100));
    yield n;
    yield* numbersDownFrom(n - 1);
  }
}

The yield* (pronounced yield-each) statement. The expression following yield* must denote another (sub)sequence. What yield* does is to insert all the elements of the subsequence into the sequence currently being constructed, as if we had an individual yield for each element.

 

我的理解是将子序列插入到当前序列中

你可能感兴趣的:(Dart)