From 35bbd44f54b2738027869d67c99f55c742945a5e Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Sun, 26 Apr 2015 15:01:13 +0600 Subject: Make Value_checker.validate_any return true if constraint list is empty (i.e. no constraints means anything goes). --- src/value_checker.ml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/value_checker.ml b/src/value_checker.ml index 245b769..1c19c3d 100644 --- a/src/value_checker.ml +++ b/src/value_checker.ml @@ -17,8 +17,16 @@ let validate_value validators value_constraint value = | _ -> false with Not_found -> raise (Bad_validator t) -let rec validate_any validators constraints value = +(* If no constraints given, consider it valid. + Otherwise consider it valid if it satisfies at least + one constraint *) +let validate_any validators constraints value = + let rec aux validators constraints value = + match constraints with + | [] -> false + | c :: cs -> if validate_value validators c value then true + else aux validators cs value + in match constraints with - | [] -> false - | c :: cs -> if validate_value validators c value then true - else validate_any validators cs value + | [] -> true + | _ -> aux validators constraints value -- cgit v1.2.3