[svn] r7350: nemerle/trunk/lib: AssemblyInfo.n narray.n

VladD2 svnadmin at nemerle.org
Mon Jan 29 00:14:18 CET 2007


Log:
Fix bug in FoldRighr() and add FilterToArray() method.

Author: VladD2
Date: Mon Jan 29 00:14:16 2007
New Revision: 7350

Modified:
   nemerle/trunk/lib/AssemblyInfo.n
   nemerle/trunk/lib/narray.n

Modified: nemerle/trunk/lib/AssemblyInfo.n
==============================================================================
--- nemerle/trunk/lib/AssemblyInfo.n	(original)
+++ nemerle/trunk/lib/AssemblyInfo.n	Mon Jan 29 00:14:16 2007
@@ -26,13 +26,21 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+using System.Reflection;
+using System.Runtime.CompilerServices;
 
-[assembly: System.Reflection.AssemblyTitle("Nemerle Library")]
-[assembly: System.Reflection.AssemblyDescription("Nemerle (http://nemerle.org) Functional Library")]
-[assembly: System.Reflection.AssemblyCompany("University of Wroclaw")]
-[assembly: System.Reflection.AssemblyProduct("Nemerle Library")]
-[assembly: System.Reflection.AssemblyCopyright("Copyright @ University of Wroclaw 2003-2007")]
+[assembly: AssemblyTitle("Nemerle Library")]
+[assembly: AssemblyDescription("Nemerle (http://nemerle.org) Functional Library")]
+[assembly: AssemblyCompany("University of Wroclaw")]
+[assembly: AssemblyProduct("Nemerle Library")]
+[assembly: AssemblyCopyright("Copyright @ University of Wroclaw 2003-2007")]
 
 [assembly: Nemerle.Utility.AssemblyVersionFromSVN("0.9.3.SVN")]
 [assembly: System.Runtime.InteropServices.ComVisible (false)]
 
+[assembly: CompilationRelaxations(8)]
+[assembly: DefaultDependency(LoadHint.Always)]
+[assembly: StringFreezing]
+[assembly: System.Security.AllowPartiallyTrustedCallers]
+
+

Modified: nemerle/trunk/lib/narray.n
==============================================================================
--- nemerle/trunk/lib/narray.n	(original)
+++ nemerle/trunk/lib/narray.n	Mon Jan 29 00:14:16 2007
@@ -136,7 +136,7 @@
       : TAccumulator
     {
       def ary = source.ToArray ();
-      for (mutable i = ary.Length - 1; i <= 0; i--)
+      for (mutable i = ary.Length - 1; i >= 0; i--)
         ini = convert(ary[i], ini);
       
       ini
@@ -285,6 +285,39 @@
       }
     }
 
+    InternalMapToArrayFiltered[From, To] (
+      source  : array[From],
+      isMatch : From -> bool,
+      convert : From -> To
+    )
+      : array [To]
+    {
+      def dest = SCG.List(source.Length);
+
+      foreach (elem when isMatch(elem) in source)
+        dest.Add (convert (elem));
+        
+      dest.ToArray()
+    }
+
+    /// Convert sequence to array with filtration.
+    public MapToArrayFiltered[From, To] (
+      this source : array[From],
+      isMatch : From -> bool,
+      convert : From -> To
+    ) : array [To]
+    {
+      if (source == null || source.Length == 0)
+        array(0)
+      else if (source.Length == 1)
+      {
+        def tmp = source[0];
+        if (isMatch(tmp)) array[convert(tmp)] else array(0)
+      }
+      else
+        InternalMapToArrayFiltered(source, isMatch, convert)
+    }
+
     /** Convert sequence to array with filtration. */
     public MapToArrayFiltered[From, To] (
       this source : SCG.IEnumerable [From],
@@ -295,6 +328,7 @@
       match (source)
       {
         | null => array (0);
+        | ary is array [From] => InternalMapToArrayFiltered(ary, isMatch, convert)
         | _ =>
           def dest = SCG.List();
 
@@ -372,6 +406,49 @@
     {
       $[ x | x in seq, predicate (x) ]
     }
+
+    /// Convert sequence to array with filtration.
+    public FilterToArray[T] (
+      this source : array[T],
+      isMatch : T -> bool
+    ) : array [T]
+    {
+      if (source == null || source.Length == 0)
+        array(0)
+      else if (source.Length == 1)
+      {
+        def tmp = source[0];
+        if (isMatch(tmp)) array[tmp] else array(0)
+      }
+      else
+        InternalFilterToArray(source, isMatch)
+    }
+    
+    public FilterToArray [T] (this source : SCG.IEnumerable [T], isMatch : T -> bool) : array [T]
+    {
+      match (source)
+      {
+        | null             => array (0);
+        | ary is array [T] => InternalFilterToArray (ary, isMatch)
+        | _                =>
+          def dest = SCG.List();
+
+          foreach (elem when isMatch(elem) in source)
+            dest.Add (elem);
+            
+          dest.ToArray()
+      }
+    }
+
+    InternalFilterToArray[T] (source : array [T], isMatch : T -> bool) : array [T]
+    {
+      def dest = SCG.List(source.Length);
+
+      foreach (elem when isMatch(elem) in source)
+        dest.Add (elem);
+        
+      dest.ToArray()
+    }
   }
   
   /**



More information about the svn mailing list