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); }
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)); }
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))); }
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))); }
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))); }
public static FPList <T> Pop <T>(this FPList <T> head) { return(head.Next); }
public static FPList <T> Push <T>(this FPList <T> head, T value) { return(new FPList <T>(value, head)); }
public static int Length <T>(this FPList <T> head) { return(head == null ? 0 : 1 + head.Next.Length()); }
public FPList(T value, FPList <T> next) { Value = value; Next = next; }