bugfix in Sequence.take

This commit is contained in:
Simon Cruanes 2013-10-03 21:54:51 +02:00
parent ad23803a4a
commit 049fe898ce

View file

@ -329,11 +329,13 @@ exception ExitSequence
(** Take at most [n] elements from the sequence *) (** Take at most [n] elements from the sequence *)
let take n seq = let take n seq =
let count = ref 0 in let count = ref 0 in
fun k -> if n = 0 then empty
else fun k ->
try try
seq seq (fun x ->
(fun x -> if !count < n then begin incr count; k x end incr count;
else raise ExitSequence) k x;
if !count = n then raise ExitSequence)
with ExitSequence -> () with ExitSequence -> ()
(** Drop the [n] first elements of the sequence *) (** Drop the [n] first elements of the sequence *)