iterate method

  1. @override
  2. @useResult
Iterable<T> iterate({
  1. required T by(
    1. T current
    ),
  2. bool ascending = true,
})
override

Returns a lazy Iterable by stepping through this range using by.

The returned Iterable is lazy and potentially infinite.

final range = Interval.closedOpen(0, 5);
range.iterate(by: (e) => e + 1).toList(); // [0, 1, 2, 3, 4]

Implementation

@override
@useResult Iterable<T> iterate({required T Function(T current) by, bool ascending = true}) sync* {
  final initial = ascending ? (min.open ? by(min.value) : min.value) : (max.open ? by(max.value) : max.value);
  for (var current = initial; contains(current); current = by(current)) {
    yield current;
  }
}