[MLton-commit] r5917
Vesa Karvonen
vesak at mlton.org
Tue Aug 21 12:22:31 PDT 2007
Added findSome for linear searching of buffers.
----------------------------------------------------------------------
U mltonlib/trunk/com/ssh/extended-basis/unstable/detail/sequence/mk-buffer-common.fun
U mltonlib/trunk/com/ssh/extended-basis/unstable/public/sequence/buffer.sig
----------------------------------------------------------------------
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/detail/sequence/mk-buffer-common.fun
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/detail/sequence/mk-buffer-common.fun 2007-08-21 15:42:18 UTC (rev 5916)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/detail/sequence/mk-buffer-common.fun 2007-08-21 19:22:30 UTC (rev 5917)
@@ -87,4 +87,14 @@
fun toVector ? = to V.tabulate ?
fun toString ? = to CV.tabulate ?
end
+
+ fun findSome p b = let
+ fun lp i = if length b < i
+ then NONE
+ else case p (sub (b, i))
+ of NONE => lp (i+1)
+ | result => result
+ in
+ lp 0
+ end
end
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/public/sequence/buffer.sig
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/public/sequence/buffer.sig 2007-08-21 15:42:18 UTC (rev 5916)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/public/sequence/buffer.sig 2007-08-21 19:22:30 UTC (rev 5917)
@@ -69,6 +69,15 @@
* 0} or {length b <= i}, then the {Subscript} exception is raised.
*)
+ (** == Iterators == *)
+
+ val findSome : ('a -> 'b Option.t) -> 'a t -> 'b Option.t
+ (**
+ * Iterates over the buffer from the beginning applying the given
+ * function. Returns the first {SOME b} value returned by the function
+ * or {NONE} if no such value is returned.
+ *)
+
(** == Conversions == *)
val toArray : 'a t -> 'a Array.t
More information about the MLton-commit
mailing list