Map each element in the collection.

suggest change

All collection objects contain a map method that takes a Function as an argument, which must take a single argument. This returns an Iterable backed by the collection. When the Iterable is iterated, each step calls the function with a new element of the collection, and the result of the call becomes the next element of the iteration.

You can turn an Iterable into a collection again by using the Iterable.toSet() or Iterable.toList() methods, or by using a collection constructor which takes an iterable like Queue.from or List.from.


main() {
  var cats = [
    'Scottish Fold',
    'Domestic Shorthair'

  print(cats); // [Abyssinian, Scottish Fold, Domestic Shorthair]

  var catsInReverse = cat) {
    return new String.fromCharCodes(cat.codeUnits.reversed);
  .toList(); // [nainissybA, dloF hsittocS, riahtrohS citsemoD]


See dartpad example here:

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents