diff --git a/src/data/CCRAL.ml b/src/data/CCRAL.ml index 65397b92..870e30e4 100644 --- a/src/data/CCRAL.ml +++ b/src/data/CCRAL.ml @@ -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)