Movatterモバイル変換


[0]ホーム

URL:


menu
  1. Dart
  2. dart:collection
  3. ListBase<E>
  4. map<T> method
map
description

map<T> method

Iterable<T>map<T>(
  1. Tf(
    1. Eelement
    )
)
override

The current elements of this iterable modified bytoElement.

Returns a new lazyIterable with elements that are created bycallingtoElement on each element of thisIterable initeration order.

The returned iterable is lazy, so it won't iterate the elements ofthis iterable until it is itself iterated, and then it will applytoElement to create one element at a time.The converted elements are not cached.Iterating multiple times over the returnedIterablewill invoke the suppliedtoElement function once per elementfor on each iteration.

Methods on the returned iterable are allowed to omit callingtoElementon any element where the result isn't needed.For example,elementAt may calltoElement 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

Iterable<T> map<T>(T f(E element)) => MappedListIterable<E, T>(this, f);
  1. Dart
  2. dart:collection
  3. ListBase<E>
  4. map<T> method
ListBase class

[8]ページ先頭

©2009-2025 Movatter.jp