diff options
author | Daniil Baturin <daniil@baturin.org> | 2015-02-28 08:56:58 +0600 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2015-02-28 08:56:58 +0600 |
commit | 8e52169fb45931873679b85491bbf179cc18c0d2 (patch) | |
tree | db93141d62d49a82d6ea37d3d56f406b2d086a1b /src | |
parent | ecdb14837e06dcc826bc9c1d9c7b939da3fb28b1 (diff) | |
download | vyconf-8e52169fb45931873679b85491bbf179cc18c0d2.tar.gz vyconf-8e52169fb45931873679b85491bbf179cc18c0d2.zip |
Use vylist module in vytree for fancy list operations.
Diffstat (limited to 'src')
-rw-r--r-- | src/vytree.ml | 33 |
1 files changed, 5 insertions, 28 deletions
diff --git a/src/vytree.ml b/src/vytree.ml index af0dee0..6a97211 100644 --- a/src/vytree.ml +++ b/src/vytree.ml @@ -18,35 +18,13 @@ let name_of_node node = node.name let data_of_node node = node.data let children_of_node node = node.children -let rec find_child_in_list children name = - match children with - | [] -> None - | c :: cs -> if c.name = name then (Some c) - else find_child_in_list cs name - -let rec remove_child_from_list children name = - match children with - | [] -> [] - | c :: cs -> if c.name = name then cs - else c :: (remove_child_from_list cs name) - -let rec replace_child_in_list children child = - match children with - | [] -> [] - | c :: cs -> if c.name = child.name then child :: cs - else replace_child_in_list cs child - -let extract_child children name = - find_child_in_list children name, - remove_child_from_list children name - let insert_immediate_child node name data = let new_node = make name data in let children' = node.children @ [new_node] in { node with children = children' } let delete_immediate_child node name = - let children' = remove_child_from_list node.children name in + let children' = Vylist.remove (fun x -> x.name = name) node.children in { node with children = children' } let adopt_child node child = @@ -54,16 +32,15 @@ let adopt_child node child = let replace_child node child = let children = node.children in - let children' = replace_child_in_list children child in + let name = child.name in + let children' = Vylist.replace (fun x -> x.name = name) child children in { node with children = children' } let find_child node name = - find_child_in_list node.children name + Vylist.find (fun x -> x.name = name) node.children let rec extract_names children = - match children with - | [] -> [] - | c :: cs -> c.name :: extract_names cs + List.map (fun x -> x.name) children let list_children node = extract_names node.children |