Stream<T>.fromIterable constructor Null safety

  1. Iterable<T> elements

Creates a single-subscription stream that gets its data from elements.

The iterable is iterated when the stream receives a listener, and stops iterating if the listener cancels the subscription, or if the Iterator.moveNext method returns false or throws. Iteration is suspended while the stream subscription is paused.

If calling Iterator.moveNext on elements.iterator throws, the stream emits that error and then it closes. If reading Iterator.current on elements.iterator throws, the stream emits that error, but keeps iterating.


final numbers = [1, 2, 3, 5, 6, 7];
final stream = Stream.fromIterable(numbers);


factory Stream.fromIterable(Iterable<T> elements) {
  return new _GeneratedStreamImpl<T>(
      () => new _IterablePendingEvents<T>(elements));