mapWithIndex<B> method
IList<B>
mapWithIndex<
B>( - B f(
- int i,
- A a
)
)
override
Implementation
@override IList<B> mapWithIndex<B>(B f(int i, A a)) {
final IList<B> bNil = nil();
if (!_isCons()) {
return bNil;
}
int i = 0;
Cons<B> last = new Cons(f(i++, _unsafeHead()), bNil);
if (!_unsafeTail()._isCons()) {
return last;
}
final result = last;
var current = _unsafeTail();
while (current._isCons()) {
final next = new Cons(f(i++, current._unsafeHead()), bNil);
last._unsafeSetTail(next);
last = next;
current = current._unsafeTail();
}
return result;
}