[MLton-commit] r5354
Vesa Karvonen
vesak at mlton.org
Tue Feb 27 12:37:39 PST 2007
A few useful additions.
----------------------------------------------------------------------
U mltonlib/trunk/com/ssh/misc-util/unstable/node.sml
U mltonlib/trunk/com/ssh/misc-util/unstable/queue.sig
U mltonlib/trunk/com/ssh/misc-util/unstable/queue.sml
----------------------------------------------------------------------
Modified: mltonlib/trunk/com/ssh/misc-util/unstable/node.sml
===================================================================
--- mltonlib/trunk/com/ssh/misc-util/unstable/node.sml 2007-02-27 15:45:43 UTC (rev 5353)
+++ mltonlib/trunk/com/ssh/misc-util/unstable/node.sml 2007-02-27 20:37:22 UTC (rev 5354)
@@ -88,6 +88,21 @@
* recursively.
*)
+ val length : 'a t -> Int.t
+ (** Returns the length of the given imperative list. *)
+
+ val filter : 'a UnPr.t -> 'a t Effect.t
+ (**
+ * Drops all nodes from the imperative list whose elements do not
+ * satisfy the given predicate.
+ *)
+
+ val filterOut : 'a UnPr.t -> 'a t Effect.t
+ (**
+ * Drops all nodes from the imperative list whose elements satisfy the
+ * given predicate.
+ *)
+
val foldl : ('a * 'b -> 'b) -> 'b -> 'a t -> 'b
(**
* Folds the imperative lists with the given function and starting
@@ -165,4 +180,13 @@
NONE => INL t
| SOME (x, t') =>
if p x then INR t else find p t'
+
+ fun length n = foldl (1 <\ op + o #2) 0 n
+
+ fun filter p t =
+ case get t of
+ NONE => ()
+ | SOME (x, t') => (if p x then () else drop t ; filter p t')
+
+ fun filterOut p = filter (negate p)
end
Modified: mltonlib/trunk/com/ssh/misc-util/unstable/queue.sig
===================================================================
--- mltonlib/trunk/com/ssh/misc-util/unstable/queue.sig 2007-02-27 15:45:43 UTC (rev 5353)
+++ mltonlib/trunk/com/ssh/misc-util/unstable/queue.sig 2007-02-27 20:37:22 UTC (rev 5354)
@@ -15,6 +15,8 @@
val isEmpty : 'a t UnPr.t
+ val length : 'a t -> Int.t
+
val deque : 'a t -> 'a Option.t
val enque : 'a t -> 'a Effect.t
Modified: mltonlib/trunk/com/ssh/misc-util/unstable/queue.sml
===================================================================
--- mltonlib/trunk/com/ssh/misc-util/unstable/queue.sml 2007-02-27 15:45:43 UTC (rev 5353)
+++ mltonlib/trunk/com/ssh/misc-util/unstable/queue.sml 2007-02-27 20:37:22 UTC (rev 5354)
@@ -25,6 +25,9 @@
fun isEmpty (IN {front, ...}) =
not (isSome (N.get (!front)))
+ fun length (IN {front, ...}) =
+ N.length (!front)
+
fun enque (IN {back, ...}) =
fn a => let
val r = !back
More information about the MLton-commit
mailing list