Skip to content

Commit fee8048

Browse files
committed
T7915: add util function value_exists
1 parent 43cb046 commit fee8048

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/config_tree.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ let get_value node path =
146146
| [] -> raise Node_has_no_value
147147
| x :: _ -> x
148148

149+
let value_exists node path value =
150+
(* alert exn Vytree.get:
151+
[Vytree.Empty_path] allow raise
152+
[Vytree.Nonexistent_path] allow raise
153+
*)
154+
let node' = (Vytree.get[@alert "-exn"]) node path in
155+
let data = Vytree.data_of_node node' in
156+
Vylist.in_list data.values value
157+
149158
let delete node path value =
150159
(* raises:
151160
[Vytree.Nonexistent_path] from get_values; delete_value

src/config_tree.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ val get_value : t -> string list -> string
5252
[@@alert exn "Vytree.Nonexistent_path"]
5353
[@@alert exn "Config_tree.Node_has_no_value"]
5454

55+
val value_exists : t -> string list -> string -> bool
56+
[@@alert exn "Vytree.Empty_path"]
57+
[@@alert exn "Vytree.Nonexistent_path"]
58+
5559
val set_comment : t -> string list -> string option -> t
5660
[@@alert exn "Vytree.Empty_path"]
5761
[@@alert exn "Vytree.Nonexistent_path"]

0 commit comments

Comments
 (0)