mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-05 19:00:31 -05:00
fix stupid bug
This commit is contained in:
parent
4682f9787b
commit
f68d187142
2 changed files with 16 additions and 2 deletions
|
|
@ -313,7 +313,7 @@ let rec unfold_kont f seed k =
|
|||
match f seed with
|
||||
| None -> k []
|
||||
| Some (v, next) ->
|
||||
let k' tl = v :: k tl in
|
||||
let k' tl = k (v :: tl) in
|
||||
unfold_kont f next k'
|
||||
|
||||
let[@inline] unfold f seed =
|
||||
|
|
@ -326,7 +326,7 @@ let[@inline] unfold f seed =
|
|||
| Some (v, next) -> v :: direct (i - 1) f next
|
||||
)
|
||||
in
|
||||
direct 20 f seed
|
||||
direct 100 f seed
|
||||
|
||||
[@@@else_]
|
||||
|
||||
|
|
|
|||
|
|
@ -156,6 +156,20 @@ assert_equal ~printer:Q.Print.int (List.length l) 1_000_000;
|
|||
true
|
||||
;;
|
||||
|
||||
t ~name:"unfold3" @@ fun () ->
|
||||
let l =
|
||||
unfold
|
||||
(fun n ->
|
||||
if n < 5_000 then
|
||||
Some (n, n + 1)
|
||||
else
|
||||
None)
|
||||
0
|
||||
in
|
||||
assert_equal ~printer:Q.Print.(list int) (List.init 5000 Fun.id) l;
|
||||
true
|
||||
;;
|
||||
|
||||
t @@ fun () -> init 0 (fun _ -> 0) = [];;
|
||||
t @@ fun () -> init 1 (fun x -> x) = [ 0 ];;
|
||||
t @@ fun () -> init 1000 (fun x -> x) = 0 -- 999;;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue