Skip to content

Instantly share code, notes, and snippets.

@Atsumi3
Last active June 9, 2023 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Atsumi3/928997d9e8c6bb71eb0ea421dad460d5 to your computer and use it in GitHub Desktop.
Save Atsumi3/928997d9e8c6bb71eb0ea421dad460d5 to your computer and use it in GitHub Desktop.
[Dart] Intからその数字分のリストを生成する
extension IntExt on int {
/// 3.indexMap((idx) => "$idx!")
/// => [0!, 1!, 2!]
Iterable<T> map<T>(T Function(int idx) f) sync* {
int k = 0;
while (k < this) {
yield f(k++);
}
}
}
@Atsumi3
Copy link
Author

Atsumi3 commented Jun 9, 2023

公式のこれと同じか
List.generate(this, (idx) => "$idx!");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment