Cons<A> class
class Cons<A> extends LListBase<A> { int _length = null; final A elem; LList<A> tail; Cons(this.elem, this.tail); isNil() => false; asCons() => this; toString() => "cons($elem, $tail)"; int length() { if (_length == null) { _length = tail.length() + 1; } return _length; } }
Extends
LListBase<A> > Cons<A>
Methods
asCons() #
asCons() => this;
LList<A> filter(bool f(A)) #
inherited from LListBase
LList<A> filter(bool f(A)) { LListBuilder<A> builder = new LListBuilder<A>(); LList<A> it = this; while (!it.isNil()) { Cons<A> cons = it.asCons(); A elem = cons.elem; if (f(elem)) builder.add(elem); it = cons.tail; } return builder.build(); }
void foreach(f(A)) #
inherited from LListBase
void foreach(f(A)) { LList<A> it = this; while (!it.isNil()) { Cons<A> cons = it.asCons(); f(cons.elem); it = cons.tail; } }
isNil() #
isNil() => false;
int length() #
int length() { if (_length == null) { _length = tail.length() + 1; } return _length; }
LList map(f(A)) #
inherited from LListBase
LList map(f(A)) { LListBuilder<A> builder = new LListBuilder<A>(); LList<A> it = this; while (!it.isNil()) { Cons<A> cons = it.asCons(); A elem = cons.elem; builder.add(f(elem)); it = cons.tail; } return builder.build(); }
toString() #
Returns a string representation of this object.
docs inherited from Object
toString() => "cons($elem, $tail)";