From 3891244d49d3c65ef6da6b8644cfb9097b0d51b0 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Sun, 26 Apr 2015 16:43:21 +0600 Subject: Add Vytree.exists for checking if path exists in a tree. --- src/vytree.ml | 4 ++++ src/vytree.mli | 2 ++ 2 files changed, 6 insertions(+) (limited to 'src') diff --git a/src/vytree.ml b/src/vytree.ml index 3177e24..ed5efd2 100644 --- a/src/vytree.ml +++ b/src/vytree.ml @@ -93,6 +93,10 @@ let rec get node path = | [name] -> find_or_fail node name | name :: names -> get (find_or_fail node name) names +let exists node path = + try ignore (get node path); true + with Nonexistent_path -> false + let get_existent_path node path = let rec aux node path acc = match path with diff --git a/src/vytree.mli b/src/vytree.mli index 4f57a0e..4b52727 100644 --- a/src/vytree.mli +++ b/src/vytree.mli @@ -30,3 +30,5 @@ 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 + +val exists : 'a t -> string list -> bool -- cgit v1.2.3