mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
code review
This commit is contained in:
parent
9e6f453aff
commit
9211a01f35
1 changed files with 8 additions and 6 deletions
|
|
@ -125,16 +125,18 @@ let remove l i = _remove [] l i
|
||||||
[1;2;4] (to_list @@ remove (of_list [1;2;3;4]) 2)
|
[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
|
let x, l' = front_exn l in
|
||||||
if i=0
|
if i=0
|
||||||
then (found := Some x; List.fold_left (fun l x -> cons x l) l' prefix)
|
then (x, List.fold_left (fun l x -> cons x l) l' prefix)
|
||||||
else _get_and_remove_exn found (x::prefix) l' (i-1)
|
else _get_and_remove_exn (x::prefix) l' (i-1)
|
||||||
|
|
||||||
let get_and_remove_exn l i =
|
let get_and_remove_exn l i =
|
||||||
let found = ref None in
|
_get_and_remove_exn [] l i
|
||||||
let l' = _get_and_remove_exn found [] l i in
|
|
||||||
(Option.get !found, l')
|
(*$= & ~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
|
let rec _map_tree f t = match t with
|
||||||
| Leaf x -> Leaf (f x)
|
| Leaf x -> Leaf (f x)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue