From 482321db949bf5b5b6868a3fc8cbeaaa589578e2 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Mon, 16 Jan 2017 14:42:26 +0700 Subject: Add a trivial 'a option -> 'a -> 'a function for substituting something for a default. --- src/util.ml | 5 +++++ src/util.mli | 2 ++ 2 files changed, 7 insertions(+) (limited to 'src') diff --git a/src/util.ml b/src/util.ml index b45f011..2bac3d6 100644 --- a/src/util.ml +++ b/src/util.ml @@ -20,3 +20,8 @@ let string_of_path path = match path with | [] -> "" | x :: xs -> Printf.sprintf "%s%s" x (aux xs "") + +let substitute_default o d = + match o with + | None -> d + | Some v -> v diff --git a/src/util.mli b/src/util.mli index ec0bb73..7d78a15 100644 --- a/src/util.mli +++ b/src/util.mli @@ -1,3 +1,5 @@ val find_xml_child : string -> Xml.xml -> Xml.xml option val string_of_path : string list -> string + +val substitute_default : 'a option -> 'a -> 'a -- cgit v1.2.3