map<T> method

  1. @override
Iterable<T> map<T>(
  1. T f(
    1. Element
    )
)
override

The current elements of this iterable modified by toElement.

Returns a new lazy Iterable with elements that are created by calling toElement on each element of this Iterable in iteration order.

The returned iterable is lazy, so it won't iterate the elements of this iterable until it is itself iterated, and then it will apply toElement to create one element at a time. The converted elements are not cached. Iterating multiple times over the returned Iterable will invoke the supplied toElement function once per element for on each iteration.

Methods on the returned iterable are allowed to omit calling toElement on any element where the result isn't needed. For example, elementAt may call toElement only once.

Equivalent to:

Iterable<T> map<T>(T toElement(E e)) sync* {
  for (var value in this) {
    yield toElement(value);
  }
}

Example:

var products = jsonDecode('''
[
  {"name": "Screwdriver", "price": 42.00},
  {"name": "Wingnut", "price": 0.50}
]
''');
var values = products.map((product) => product['price'] as double);
var totalPrice = values.fold(0.0, (a, b) => a + b); // 42.5.

Implementation

@override
Iterable<T> map<T>(T Function(Element) f) => _filtered.map(f);