[svn] r6345: nemerle/trunk/lib/narray.n
malekith
svnadmin at nemerle.org
Sun May 28 10:49:24 CEST 2006
Log:
Two new utility functions: ChopFirst/LastN.
Author: malekith
Date: Sun May 28 10:49:22 2006
New Revision: 6345
Modified:
nemerle/trunk/lib/narray.n
Modified: nemerle/trunk/lib/narray.n
==============================================================================
--- nemerle/trunk/lib/narray.n (original)
+++ nemerle/trunk/lib/narray.n Sun May 28 10:49:22 2006
@@ -52,6 +52,32 @@
}
+ /** Return a fresh copy of [arr] with first [n] elements removed. */
+ public ChopFirstN ['a] (this arr : array ['a], n : int) : array ['a]
+ {
+ if (arr.Length < n)
+ throw System.ArgumentException ("NArray.ChopFirstN called for too short array")
+ else {
+ def res = array (arr.Length - n);
+ System.Array.Copy (arr, n, res, 0, res.Length);
+ res
+ }
+ }
+
+
+ /** Return a fresh copy of [arr] with last [n] elements removed. */
+ public ChopLastN ['a] (this arr : array ['a], n : int) : array ['a]
+ {
+ if (arr.Length < n)
+ throw System.ArgumentException ("NArray.LastFirstN called for too short array")
+ else {
+ def res = array (arr.Length - n);
+ System.Array.Copy (arr, 0, res, 0, res.Length);
+ res
+ }
+ }
+
+
/**
* Iterates a function over an array, passing both the array index
* and value as the iterated function parameters.
More information about the svn
mailing list