Exemplo n.º 1
0
    public static T[] ToArray <T>(this FPList <T> head)
    {
        var a = new T[head.Length()];

        for (var i = 0; i < a.Length; ++i, head = head.Next)
        {
            a[i] = head.Value;
        }
        return(a);
    }
Exemplo n.º 2
0
 public static T2 Aggregate <T, T2>(this FPList <T> head, T2 init, Func <T2, T, T2> f)
 {
     return(head == null ? init : head.Next.Aggregate(f(init, head.Value), f));
 }
Exemplo n.º 3
0
 public static FPList <T> Where <T>(this FPList <T> head, Func <T, bool> f)
 {
     return(head == null ? null : (f(head.Value) ? new FPList <T>(head.Value, head.Next.Where(f)) : head.Next.Where(f)));
 }
Exemplo n.º 4
0
 public static FPList <T2> Select <T, T2>(this FPList <T> head, Func <T, T2> f)
 {
     return(head == null ? null : new FPList <T2>(f(head.Value), head.Next.Select(f)));
 }
Exemplo n.º 5
0
 public static bool Contain <T>(this FPList <T> head, Func <T, bool> f)
 {
     return(head == null ? false : (f(head.Value) ? true : head.Next.Contain(f)));
 }
Exemplo n.º 6
0
 public static FPList <T> Pop <T>(this FPList <T> head)
 {
     return(head.Next);
 }
Exemplo n.º 7
0
 public static FPList <T> Push <T>(this FPList <T> head, T value)
 {
     return(new FPList <T>(value, head));
 }
Exemplo n.º 8
0
 public static int Length <T>(this FPList <T> head)
 {
     return(head == null ? 0 : 1 + head.Next.Length());
 }
Exemplo n.º 9
0
 public FPList(T value, FPList <T> next)
 {
     Value = value;
     Next  = next;
 }