[svn] r7295: nemerle/trunk/lib/list.n

VladD2 svnadmin at nemerle.org
Fri Jan 19 20:47:39 CET 2007


Log:
Add ToList() extension methods to IList[T].

Author: VladD2
Date: Fri Jan 19 20:47:38 2007
New Revision: 7295

Modified:
   nemerle/trunk/lib/list.n

Modified: nemerle/trunk/lib/list.n
==============================================================================
--- nemerle/trunk/lib/list.n	(original)
+++ nemerle/trunk/lib/list.n	Fri Jan 19 20:47:38 2007
@@ -675,7 +675,7 @@
       loop (x.Length - 1, [])
     }
     
-    public ToListRev ['a] (this seq : SCG.IEnumerable ['a]) : list ['a]
+    public ToListRev [T] (this seq : SCG.IEnumerable [T]) : list [T]
     {
       mutable lst = [];
       
@@ -685,7 +685,7 @@
       lst;
     }
 
-    public ToListRev ['a] (this seq : SCG.IEnumerable ['a], filter : 'a -> bool) : list ['a]
+    public ToListRev [T] (this seq : SCG.IEnumerable [T], filter : T -> bool) : list [T]
     {
       mutable lst = [];
       
@@ -696,12 +696,36 @@
       lst;
     }
 
-    public ToList ['a] (this seq : SCG.IEnumerable ['a]) : list ['a]
+    public ToList [T] (this seq : SCG.IEnumerable [T]) : list [T]
     {
       ToListRev(seq).Rev()
     }
 
-    public ToList ['a] (this seq : SCG.IEnumerable ['a], filter : 'a -> bool) : list ['a]
+    public ToList [T] (this source : SCG.IList [T]) : list [T]
+    {
+      mutable lst = [];
+      
+      for (mutable i = source.Count - 1; i >= 0; i--)
+        lst ::= source[i];
+      
+      lst;
+    }
+
+    public ToList [T] (this source : SCG.IList [T], filter : T -> bool) : list [T]
+    {
+      mutable lst = [];
+      
+      for (mutable i = source.Count - 1; i >= 0; i--)
+      {
+        def elem = source[i];
+        when (filter (elem))
+          lst ::= elem;
+      }
+      
+      lst;
+    }
+
+    public ToList [T] (this seq : SCG.IEnumerable [T], filter : T -> bool) : list [T]
     {
       ToListRev(seq, filter).Rev()
     }



More information about the svn mailing list