public int CompareTo(List1 <T> other) { var ch = CompareToT(Head, other.Head); if (CompareToT(Head, other.Head) == 0) { using (var a = Tail.ToEnumerable().SelectMany(x => x.ToEnumerable()).GetEnumerator()) { using (var b = other.Tail.ToEnumerable().SelectMany(x => x.ToEnumerable()).GetEnumerator()) { for (;;) { bool an = a.MoveNext(); bool bn = b.MoveNext(); if (an != bn) // one must have stopped - ergo, different lengths { return(an ? 1 : -1); // left/'this' continues, it's called the greater of the 2 } if (!an) // flags are equal after check above - an is false, both are false - both hit end, ergo both are equal { return(0); // bn == false. They're equal } int c = CompareToT(a.Current, b.Current); if (c != 0) // they mismatch - hit the end { return(c); } } } } } return(ch); }
// TODO - optimize this (would need structural changes to List1's privacy to enable efficient forward build). Putting this here as a placeholder so that // end-users don't scatter .Insist(.ToEnumable()) themselves public List1 <U> Select <U>(Func <T, U> f) => List1.Insist(ToEnumerable().Select(f));
public bool Equals(List1 <T> obj) => CompareTo(obj) == 0;