From 0bdfaae3f79d23c0fd560b18578043330167a2d3 Mon Sep 17 00:00:00 2001
From: Daniil Baturin <daniil@baturin.org>
Date: Sun, 1 Mar 2015 00:45:42 +0600
Subject: Add get_child and some tests for it.

---
 src/vytree/vytree.ml | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

(limited to 'src/vytree/vytree.ml')

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
-- 
cgit v1.2.3