diff --git a/src/core/CCList.ml b/src/core/CCList.ml index d5d791ac..0d5d866f 100644 --- a/src/core/CCList.ml +++ b/src/core/CCList.ml @@ -313,7 +313,7 @@ let rec unfold_kont f seed k = match f seed with | None -> k [] | Some (v, next) -> - let k' tl = v :: tl in + let k' tl = v :: k tl in unfold_kont f next k' let[@inline] unfold f seed = diff --git a/tests/core/t_list.ml b/tests/core/t_list.ml index b32aef65..05de8854 100644 --- a/tests/core/t_list.ml +++ b/tests/core/t_list.ml @@ -131,17 +131,18 @@ q = (List.rev l, flat_map (fun x -> [ x; x + 10 ]) l)) ;; -t @@ fun () -> +eq ~printer:Q.Print.(list int) ~name:"unfold1" [ 0; 2; 4; 6; 8; 10 ] +@@ let f x = if x <= 5 then Some (2 * x, x + 1) else None in -unfold f 0 = [ 0; 2; 4; 6; 8; 10 ] +unfold f 0 ;; -t @@ fun () -> +t ~name:"unfold2" @@ fun () -> let l = unfold (fun n ->