Yield* in dart

import 'dart:async';

main(List<String> 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.

 

我的理解是將子序列插入到當前序列中

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章