Пример #1
0
        public CachedSequence <T> Reverse()
        {
            CachedSequence <T> newHead = new CachedSequence <T> (Head);
            CachedSequence <T> t       = Tail;

            while (t != null)
            {
                newHead = new CachedSequence <T> (t.Head, newHead);
                t       = t.Tail;
            }
            return(newHead);
        }
Пример #2
0
        public T ElementAt(int index)
        {
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index");
            }
            CachedSequence <T> c = this;

            while (--index >= 0)
            {
                c = c.Tail;
            }
            return(c.Head);
        }
Пример #3
0
        public CachedSequence <T> Append(T value)
        {
            CachedSequence <T> start, c;

            start = c = new CachedSequence <T> (Head);

            CachedSequence <T> end = Tail;

            while (end != null)
            {
                var n = new CachedSequence <T> (end.Head);
                c.rest = Either(n);
                c      = n;
                end    = end.Tail;
            }
            c.rest = Either(new CachedSequence <T> (value));

            return(start);
        }
Пример #4
0
 Either <CachedSequence <T>, IEnumerator <T> > Either(CachedSequence <T> tail)
 {
     return(Either <CachedSequence <T>, IEnumerator <T> > .A(tail));
 }
Пример #5
0
 public CachedSequence(T head, CachedSequence <T> tail)
 {
     this.head = head;
     this.rest = tail == null ? null : Either(tail);
 }