Language: Add second, third, ... members to `ListIterable`

Created on 19 Oct 2019  Â·  2Comments  Â·  Source: dart-lang/language

Currently, when trying to get elements from a small list, you can only get hold of the first element by the list.first getter. It would be useful to have second, third, ... getters too.

I'm not saying that there should be getters up to like threehundredth, but even getters up to tenth or so would be useful.

If implemented, as far as I'm concerned, there aren't any performance or memory disadvantages during runtime of AOT compilation – if you don't use the methods, they'll be tree-shaken away.

feature

Most helpful comment

Dart will/now have extensions. We now can do that ourselves.

extension <T> on List<T> {
  T get second => this[1];
  T get third => this[2];
}

All 2 comments

Dart will/now have extensions. We now can do that ourselves.

extension <T> on List<T> {
  T get second => this[1];
  T get third => this[2];
}

Nice! I created a package for that: https://pub.dev/packages/list_accessors

Was this page helpful?
0 / 5 - 0 ratings

Related issues

munificent picture munificent  Â·  5Comments

leafpetersen picture leafpetersen  Â·  3Comments

natebosch picture natebosch  Â·  4Comments

listepo picture listepo  Â·  3Comments

jonasfj picture jonasfj  Â·  3Comments