summaryrefslogtreecommitdiff
path: root/src/vytree/vytree.ml
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2015-03-01 00:45:42 +0600
committerDaniil Baturin <daniil@baturin.org>2015-03-01 00:45:42 +0600
commit0bdfaae3f79d23c0fd560b18578043330167a2d3 (patch)
tree32e74410fc0ac6924e46f8ef8bf40bfc10ee9094 /src/vytree/vytree.ml
parent1a447ffb0794389fa62231ffb0898b68451c6aba (diff)
downloadvyconf-0bdfaae3f79d23c0fd560b18578043330167a2d3.tar.gz
vyconf-0bdfaae3f79d23c0fd560b18578043330167a2d3.zip
Add get_child and some tests for it.
Diffstat (limited to 'src/vytree/vytree.ml')
-rw-r--r--src/vytree/vytree.ml18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/vytree/vytree.ml b/src/vytree/vytree.ml
index 6a97211..7ee3e65 100644
--- a/src/vytree/vytree.ml
+++ b/src/vytree/vytree.ml
@@ -78,3 +78,21 @@ let rec delete_child node path =
| Some next_child' ->
let new_node = delete_child next_child' names in
replace_child node new_node
+
+let rec get_child node path =
+ match path with
+ | [] -> raise Empty_path
+ | [name] ->
+ begin
+ let child = find_child node name in
+ match child with
+ | None -> raise Nonexistent_path
+ | Some child' -> child'
+ end
+ | name :: names ->
+ begin
+ let next_child = find_child node name in
+ match next_child with
+ | None -> raise Nonexistent_path
+ | Some child' -> get_child child' names
+ end