code review

This commit is contained in:
Josh Berdine 2021-04-16 15:15:11 +01:00
parent 9e6f453aff
commit 9211a01f35

View file

@ -125,16 +125,18 @@ let remove l i = _remove [] l i
[1;2;4] (to_list @@ remove (of_list [1;2;3;4]) 2)
*)
let rec _get_and_remove_exn found prefix l i =
let rec _get_and_remove_exn prefix l i =
let x, l' = front_exn l in
if i=0
then (found := Some x; List.fold_left (fun l x -> cons x l) l' prefix)
else _get_and_remove_exn found (x::prefix) l' (i-1)
then (x, List.fold_left (fun l x -> cons x l) l' prefix)
else _get_and_remove_exn (x::prefix) l' (i-1)
let get_and_remove_exn l i =
let found = ref None in
let l' = _get_and_remove_exn found [] l i in
(Option.get !found, l')
_get_and_remove_exn [] l i
(*$= & ~printer:Q.Print.(pair int (list int))
(3,[1;2;4]) (CCPair.map_snd to_list @@ get_and_remove_exn (of_list [1;2;3;4]) 2)
*)
let rec _map_tree f t = match t with
| Leaf x -> Leaf (f x)