[svn] r7068: nemerle/trunk: lib/narray.n ncc/typing/Typer.n
VladD2
svnadmin at nemerle.org
Thu Dec 7 07:12:06 CET 2006
Log:
Add Fold() extension methods (for IEnumerable[T])
Author: VladD2
Date: Thu Dec 7 07:11:54 2006
New Revision: 7068
Modified:
nemerle/trunk/lib/narray.n
nemerle/trunk/ncc/typing/Typer.n
Modified: nemerle/trunk/lib/narray.n
==============================================================================
--- nemerle/trunk/lib/narray.n (original)
+++ nemerle/trunk/lib/narray.n Thu Dec 7 07:11:54 2006
@@ -33,6 +33,28 @@
{
public module NCollectionsUtils
{
+ public FoldLeft [A, B] (this source : SCG.IEnumerable [B], mutable ini : A, f : B * A -> A) : A
+ {
+ foreach (value in source)
+ ini = f(value, ini);
+
+ ini
+ }
+
+ public FoldRight [A, B] (this source : SCG.IEnumerable [B], mutable ini : A, f : B * A -> A) : A
+ {
+ def ary = source.ToArray ();
+ for (mutable i = ary.Length - 1; i <= 0; i--)
+ ini = f(ary[i], ini);
+
+ ini
+ }
+
+ public Fold [A, B] (this source : SCG.IEnumerable [B], mutable ini : A, f : B * A -> A) : A
+ {
+ FoldLeft (source, ini, f)
+ }
+
public BinarySearch [TElem] (
this collection : SCG.IList [TElem],
lo : int,
Modified: nemerle/trunk/ncc/typing/Typer.n
==============================================================================
More information about the svn
mailing list