Help us understand the problem. What is going on with this article?

Flutter DartでIndex付きのmapを簡単に行うExtension

Extension

ちょいちょいmapをindex付きで使いたいことがあったので作りました。英語的にはEnumeratedMapのほうが正しいんだろうか…。

forEach のほうがメモリ食うけど高速かなと思いforEachで書いてます。

extension IndexedMap<T, E> on List<T> {
  List<E> indexedMap<E>(E Function(int index, T item) function) {
    final list = <E>[];
    asMap().forEach((index, element) {
      list.add(function(index, element));
    });
    return list;
  }
}

// example
final List<int> list = [1, 2, 3];
list.indexedMap((index, element) => index.toString() + element.toString());
_mogaming
Developer | Firebase系YouTuber moga.page.link/yt | プロトタイプ開発や新規サービス立ち上げが主な仕事 | ex) 実験, DeNA
https://twitter.com/_mogaming
engineerlife
技術力をベースに人生を謳歌する人たちのコミュニティです。
https://community.camp-fire.jp/projects/view/280040
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away