onEach method

Iterable<T> onEach(
  1. void action(
    1. T element
    )
)

Applies the given action on each element and also returns the whole Iterable without modifying it.

Example:

var sum = [1, 2, 3].onEach(print).sum(); // sum = 6 (also prints each number)

Implementation

Iterable<T> onEach(void Function(T element) action) sync* {
  ArgumentError.checkNotNull(action, 'action');
  final it = iterator;
  while (it.moveNext()) {
    action(it.current);
    yield it.current;
  }
}