diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/vytree.ml | 11 | ||||
-rw-r--r-- | src/vytree.mli | 2 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/vytree.ml b/src/vytree.ml index 10ccf0e..3177e24 100644 --- a/src/vytree.ml +++ b/src/vytree.ml @@ -92,3 +92,14 @@ let rec get node path = | [] -> raise Empty_path | [name] -> find_or_fail node name | name :: names -> get (find_or_fail node name) names + +let get_existent_path node path = + let rec aux node path acc = + match path with + | [] -> acc + | name :: names -> + let child = find node name in + match child with + | None -> acc + | Some c -> aux c names (name :: acc) + in List.rev (aux node path []) diff --git a/src/vytree.mli b/src/vytree.mli index 8224fdd..2ce7a36 100644 --- a/src/vytree.mli +++ b/src/vytree.mli @@ -25,3 +25,5 @@ val update : 'a t -> string list -> 'a -> 'a t val list_children : 'a t -> string list val get : 'a t -> string list -> 'a t + +val get_existent_path : 'a t -> string list -> string list |