[svn] r6612: nemerle/trunk/lib/narray.n
VladD2
svnadmin at nemerle.org
Mon Sep 4 19:28:06 CEST 2006
Log:
Change extension methods names.
Author: VladD2
Date: Mon Sep 4 19:28:03 2006
New Revision: 6612
Modified:
nemerle/trunk/lib/narray.n
Modified: nemerle/trunk/lib/narray.n
==============================================================================
--- nemerle/trunk/lib/narray.n (original)
+++ nemerle/trunk/lib/narray.n Mon Sep 4 19:28:03 2006
@@ -97,8 +97,7 @@
/**
* Convert a collection of one type to an array of another type.
*/
- public ToArray[From, To] (this source : SCG.ICollection[From],
- f : From -> To) : array [To]
+ public MapToArray[From, To] (this source : SCG.ICollection[From], f : From -> To) : array [To]
{
if (source == null)
array (0)
@@ -106,19 +105,26 @@
{
def tmp = array (source.Count);
source.CopyTo (tmp, 0);
- tmp.ConvertTo (f)
+ tmp.Map (f)
}
}
/**
+ * Convert collection of one type to array of another type. (Alias for MapToArray)
+ */
+ public ConvertToArray [From, To] (this source : SCG.ICollection[From], f : From -> To) : array [To]
+ {
+ MapToArray (source, f)
+ }
+
+ /**
* Convert a sequence of one type to an array of another type.
*/
- public ToArray[From, To] (this source : SCG.IEnumerable [From],
- f : From -> To) : array [To]
+ public MapToArray[From, To] (this source : SCG.IEnumerable [From], f : From -> To) : array [To]
{
match (source)
{
- | coll is SCG.ICollection[From] => coll.ToArray (f);
+ | coll is SCG.ICollection[From] => coll.MapToArray (f);
| null => array (0);
| _ =>
def dest = SCG.List();
@@ -130,6 +136,14 @@
}
}
+ /**
+ * Convert sequence of one type to array of another type. (Alias for MapToArray)
+ */
+ public ConvertToArray[From, To] (this source : SCG.IEnumerable [From], f : From -> To) : array [To]
+ {
+ MapToArray(source, f)
+ }
+
/** Convert sequence to array with filtration. */
public ToArrayFiltered[T] (this source : SCG.IEnumerable [T], isMatch : T -> bool) : array [T]
{
@@ -140,11 +154,40 @@
def dest = SCG.List();
foreach (elem when isMatch(elem) in source)
- dest.Add(elem);
+ dest.Add (elem);
dest.ToArray()
}
}
+
+ /** Convert sequence to array with filtration. */
+ public MapToArrayFiltered[From, To] (
+ this source : SCG.IEnumerable [From],
+ isMatch : From -> bool,
+ f : From -> To
+ ) : array [To]
+ {
+ match (source)
+ {
+ | null => array (0);
+ | _ =>
+ def dest = SCG.List();
+
+ foreach (elem when isMatch(elem) in source)
+ dest.Add (f (elem));
+
+ dest.ToArray()
+ }
+ }
+
+ public ConvertToArrayFiltered[From, To] (
+ this source : SCG.IEnumerable [From],
+ isMatch : From -> bool,
+ f : From -> To
+ ) : array [To]
+ {
+ MapToArrayFiltered(source, isMatch, f)
+ }
}
/**
@@ -212,19 +255,27 @@
loop (0)
}
- public Map ['a, 'b] (this ar : array ['a], f : 'a -> 'b) : array ['b]
+ public Map [From, To] (this from : array [From], f : From -> To) : array [To]
{
- def result = array (ar.Length);
+ def result = array (from.Length);
- for (mutable i = 0; i < ar.Length; ++i)
- result [i] = f (ar [i]);
+ for (mutable i = 0; i < from.Length; ++i)
+ result [i] = f (from [i]);
result
}
- public Map ['a, 'b] (res_type : System.Type, ar : array ['a], f : 'a -> 'b) : array ['b]
+ /**
+ * Convert array of one type to other. (This is a alias for Map().)
+ */
+ public ConvertAll [From, To] (this source : array [From], f : From -> To) : array [To]
{
- assert (typeof ('b).Equals (res_type));
+ source.Map (f);
+ }
+
+ public Map [From, To] (res_type : System.Type, ar : array [From], f : From -> To) : array [To]
+ {
+ assert (typeof (To).Equals (res_type));
Map (ar, f)
}
@@ -476,19 +527,6 @@
(source : object) :> array [Base]
}
- /**
- * Convert array of one type to other.
- */
- public ConvertTo[From, To] (this source : array [From], f : From -> To) : array [To]
- {
- mutable dest = array(source.Length);
-
- for (mutable i = 0; i < source.Length; i++)
- dest[i] = f (source[i]);
-
- dest;
- }
-
/** Attention! It's inplace sort. */
public SortInplace[T] (this source : array [T], comparison : System.Comparison[T]) : array [T]
{
@@ -519,7 +557,7 @@
/** Convert array to string. */
public ToString['a] (this source : array ['a], separator : string) : string
{
- string.Join(separator, source.ConvertTo(value => value.ToString()));
+ string.Join(separator, source.Map(value => value.ToString()));
}
}
} /* end of namespace */
More information about the svn
mailing list