indexed method
Iterable<Indexed<E> >
indexed({
- int start = 0,
- int step = 1,
- @Deprecated('Use `start` instead of `offset`') int? offset,
Returns a iterable that combines the index and value of this Iterable.
By default the index is zero based, but an arbitrary offset
can be
provided.
For example, the expression
['a', 'b'].indexed(start: 1)
.map((each) => '${each.index}: ${each.value}')
.join(', ');
returns
'1: a, 2: b'
Implementation
Iterable<Indexed<E>> indexed({
int start = 0,
int step = 1,
@Deprecated('Use `start` instead of `offset`') int? offset,
}) sync* {
var index = offset ?? start;
for (final element in this) {
yield Indexed<E>(index, element);
index += step;
}
}