Last active
June 9, 2023 09:55
-
-
Save Atsumi3/928997d9e8c6bb71eb0ea421dad460d5 to your computer and use it in GitHub Desktop.
[Dart] Intからその数字分のリストを生成する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
公式のこれと同じか
List.generate(this, (idx) => "$idx!");