1
// Enumerable.cs created with MonoDevelop
2
// User: david at 12:49 PM 10/21/2008
4
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
8
using System.Collections.Generic;
12
public static class Enumerable
15
public static T Aggregate<T> (IEnumerable<T> self, Func<T, T, T> f)
19
foreach (T x in self) {
20
acc = first ? x : f (acc, x);
26
public static T2 Aggregate<T1, T2> (IEnumerable<T1> self, T2 acc, Func<T2, T1, T2> f)
28
foreach (T1 x in self)
33
public static T3 Aggregate<T1, T2, T3> (IEnumerable<T1> self, T2 acc, Func<T2, T1, T2> f, Func<T2, T3> f2)
35
return f2 (Aggregate (self, acc, f));
38
public static bool All<T> (this IEnumerable<T> self, Func<T, bool> p)
41
if (!p (x)) return false;
45
public static bool Any<T> (this IEnumerable<T> self)
52
public static bool Any<T> (this IEnumerable<T> self, Func<T, bool> p)
55
if (p (x)) return true;
59
public static IEnumerable<T2> Select<T1, T2> (this IEnumerable<T1> self, Func<T1, T2> f)
61
List<T2> xs = new List<T2> ();
62
foreach (T1 x in self)
67
public static IEnumerable<T> Where<T> (this IEnumerable<T> self, Func<T, bool> p)
69
List<T> xs = new List<T> ();
71
if (p (x)) xs.Add (x);