bind<B> method
Implementation
@override IList<B> bind<B>(Function1<A, IList<B>> f) {
final IList<B> bNil = nil();
if (!_isCons()) {
return bNil;
}
Cons<B>? result = null;
IList<B>? resultHead = null;
var current = this;
var sub = f(current._unsafeHead());
while(current._isCons() && !sub._isCons()) {
current = current._unsafeTail();
if (current._isCons()) {
sub = f(current._unsafeHead());
}
}
if (sub._isCons()) {
result = new Cons(sub._unsafeHead(), bNil);
resultHead = result;
sub = sub._unsafeTail();
while(sub._isCons()) {
final next = new Cons(sub._unsafeHead(), bNil);
result!._unsafeSetTail(next);
result = next;
sub = sub._unsafeTail();
}
current = current._unsafeTail();
}
while (current._isCons()) {
sub = f(current._unsafeHead());
while(sub._isCons()) {
final next = new Cons(sub._unsafeHead(), bNil);
result!._unsafeSetTail(next);
result = next;
sub = sub._unsafeTail();
}
current = current._unsafeTail();
}
return resultHead ?? bNil;
}