[svn] r7699: nemerle/trunk: lib/narray.n ncc/testsuite/positive/ExpensionMethods.n

VladD2 svnadmin at nemerle.org
Sun Jun 10 20:00:57 CEST 2007


Log:
Add IsEmpty() extension method.

Author: VladD2
Date: Sun Jun 10 20:00:55 2007
New Revision: 7699

Added:
   nemerle/trunk/ncc/testsuite/positive/ExpensionMethods.n
Modified:
   nemerle/trunk/lib/narray.n

Modified: nemerle/trunk/lib/narray.n
==============================================================================
--- nemerle/trunk/lib/narray.n	(original)
+++ nemerle/trunk/lib/narray.n	Sun Jun 10 20:00:55 2007
@@ -35,6 +35,28 @@
 {
   public module NCollectionsUtils
   {
+    public IsEmpty   (this seq : System.Collections.ICollection) : bool { seq.Count == 0 }
+    public IsEmpty[T](this seq : array[T])                       : bool { seq.Length == 0 }
+    public IsEmpty[T](this seq : list[T])                        : bool
+    {
+      | []     => true
+      | _ :: _ => false
+      | null   => true
+    }
+    
+    public IsEmpty[T](this seq : SCG.IEnumerable[T])             : bool
+    {
+      | []                                    => true
+      | _ :: _                                => false
+      | ary is array[T]                       => IsEmpty(ary)
+      | col is System.Collections.ICollection => IsEmpty(col)
+      | null                                  => true
+      | _                                     =>
+        foreach (_ in seq) // This for call IDisposable...
+          Nemerle.Imperative.Return(false);
+        true
+    }
+
     // Lazy functions
     //
 

Added: nemerle/trunk/ncc/testsuite/positive/ExpensionMethods.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/ncc/testsuite/positive/ExpensionMethods.n	Sun Jun 10 20:00:55 2007
@@ -0,0 +1,36 @@
+using Nemerle.IO;
+using System.Console;
+using Nemerle.Utility;
+using SCG = System.Collections.Generic;
+
+module Program
+{
+  public Main () : void
+  {
+    // IsEmpty() test
+    WriteLine(array[1].IsEmpty());
+    WriteLine(array(0).IsEmpty());
+    WriteLine([1].IsEmpty());
+    WriteLine([1].Tail.IsEmpty());
+    WriteLine(SCG.List().IsEmpty());
+    WriteLine(SCG.List(array[1, 2]).IsEmpty());
+    def dic = SCG.Dictionary();
+    dic.Add("aaa", 123);
+    WriteLine(dic.IsEmpty());
+    dic.Clear();
+    WriteLine(dic.IsEmpty());
+  }
+}
+
+/*
+BEGIN-OUTPUT
+False
+True
+False
+True
+True
+False
+False
+True
+END-OUTPUT
+*/



More information about the svn mailing list