[svn] r7561: nemerle/trunk/lib/narray.n
VladD2
svnadmin at nemerle.org
Sat Mar 31 07:59:56 CEST 2007
Log:
Add some lib functions.
Author: VladD2
Date: Sat Mar 31 07:59:55 2007
New Revision: 7561
Modified:
nemerle/trunk/lib/narray.n
Modified: nemerle/trunk/lib/narray.n
==============================================================================
--- nemerle/trunk/lib/narray.n (original)
+++ nemerle/trunk/lib/narray.n Sat Mar 31 07:59:55 2007
@@ -29,6 +29,7 @@
using Nemerle.Assertions;
using Nemerle.Collections;
using SCG = System.Collections.Generic;
+using Nemerle.Imperative;
namespace Nemerle.Utility
{
@@ -106,7 +107,7 @@
{
for (mutable i = 0; i < source.Length; i++)
when (isMatch(source[i]))
- Nemerle.Imperative.Return(i);
+ return i;
-1;
}
@@ -115,7 +116,7 @@
{ // doubling for performance reason
for (mutable i = 0; i < source.Count; i++)
when (isMatch(source[i]))
- Nemerle.Imperative.Return(i);
+ return i;
-1;
}
@@ -124,7 +125,7 @@
{ // doubling for performance reason
for (mutable i = 0; i < source.Count; i++)
when (isMatch(source[i]))
- Nemerle.Imperative.Return(i);
+ return i;
-1;
}
@@ -481,6 +482,60 @@
sb.ToString()
}
+
+ /// Return right-hand element or new object (if id does not exists).
+ public RightHand[T]([NotNull] this lst : SCG.IList[T], index : int) : T
+ where T: new()
+ {
+ def nextIndex = index + 1;
+ if (nextIndex >= lst.Count) T() else lst[nextIndex];
+ }
+
+ /// Return left-hand element or new object (if id does not exists).
+ public LeftHand[T]([NotNull] this lst : SCG.IList[T], index : int) : T
+ where T: new()
+ {
+ def nextIndex = index - 1;
+ if (nextIndex < 0) T() else lst[nextIndex];
+ }
+
+ public Reverce[T]([NotNull] this seq : SCG.IEnumerable[T]) : SCG.List[T]
+ {
+ def lst = SCG.List(seq);
+ lst.Reverse();
+ lst;
+ }
+
+ public Find[T]([NotNull] this seq : SCG.IEnumerable[T], predicate : T -> bool) : option[T]
+ {
+ foreach (item in seq)
+ when (predicate(item))
+ return Some(item);
+
+ None();
+ }
+
+ /// Find reference type object. Return reference to found objec of null.
+ public FindObject[T]([NotNull] this seq : SCG.IEnumerable[T], predicate : T -> bool) : T
+ where T : class
+ {
+ foreach (item in seq)
+ when (predicate(item))
+ return item;
+
+ null;
+ }
+
+ /* Bug 982
+ public FindValue[T]([NotNull] this seq : SCG.IEnumerable[T], predicate : T -> bool) : T?
+ where T : struct
+ {
+ foreach (item in seq)
+ when (predicate(item))
+ return item;
+
+ null;
+ }*/
}
/**
More information about the svn
mailing list