예제 #1
0
        /// <summary>
        ///   <para>Returns first n elements of the list.
        ///  Works in time and memory O(n).
        ///
        /// </para>
        /// </summary>
        public list <T> FirstN(int n)
        {
            int      num   = n;
            list <T> list  = list <T> .Nil._N_constant_object;
            list <T> list2 = this;

            while (num != 0)
            {
                if (list2 is list <T> .Cons)
                {
                    T hd = ((list <T> .Cons)list2).hd;
                    list2 = (list <T>)((list <T> .Cons)list2).tl;
                    int      arg_6A_0 = checked (num - 1);
                    list <T> arg_69_0 = (list <T>) new list <T> .Cons(hd, list);

                    list = arg_69_0;
                    num  = arg_6A_0;
                }
                else
                {
                    if (list2 == list <T> .Nil._N_constant_object)
                    {
                        throw new ArgumentException("NList.FirstN called for too short list");
                    }
                    throw new MatchFailureException();
                }
            }
            return(NList.Rev <T>(list));
        }
예제 #2
0
 /// <summary>
 ///   <para>Returns reversed list, i.e. Rev([1,2,3]) = [3,2,1].
 ///  Works in time and memory O(n).
 ///
 /// </para>
 /// </summary>
 public list <T> Rev()
 {
     return(NList.Rev <T>(this));
 }