mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
bugfix in Sequence.take
This commit is contained in:
parent
0f972ba6a2
commit
b3c76eb897
1 changed files with 7 additions and 5 deletions
12
sequence.ml
12
sequence.ml
|
|
@ -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
|
||||||
try
|
else fun k ->
|
||||||
seq
|
try
|
||||||
(fun x -> if !count < n then begin incr count; k x end
|
seq (fun x ->
|
||||||
else raise ExitSequence)
|
incr count;
|
||||||
|
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 *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue