From 8caa65f953642cd8fe12ca6493b25a463093f30b Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Wed, 3 Jun 2015 15:56:48 +0600 Subject: Add get_data function, a shortcut for getting a data of node at specified path. Mainly for quickly getting data from a reference tree. --- src/vytree.ml | 2 ++ src/vytree.mli | 2 ++ 2 files changed, 4 insertions(+) (limited to 'src') diff --git a/src/vytree.ml b/src/vytree.ml index 93d3d71..b5dcba6 100644 --- a/src/vytree.ml +++ b/src/vytree.ml @@ -97,6 +97,8 @@ let rec get node path = | [name] -> find_or_fail node name | name :: names -> get (find_or_fail node name) names +let get_data node path = data_of_node @@ get node path + let exists node path = try ignore (get node path); true with Nonexistent_path -> false diff --git a/src/vytree.mli b/src/vytree.mli index e912922..6a7eda1 100644 --- a/src/vytree.mli +++ b/src/vytree.mli @@ -31,4 +31,6 @@ val get : 'a t -> string list -> 'a t val get_existent_path : 'a t -> string list -> string list +val get_data : 'a t -> string list -> 'a + val exists : 'a t -> string list -> bool -- cgit v1.2.3