diff options
| -rw-r--r-- | lib/input.ml | 6 | ||||
| -rw-r--r-- | lib/util.ml | 16 |
2 files changed, 17 insertions, 5 deletions
diff --git a/lib/input.ml b/lib/input.ml index b233292..208cf4d 100644 --- a/lib/input.ml +++ b/lib/input.ml @@ -20,17 +20,13 @@ end module Latest = struct module Cmd = struct - type 'a non_empty_list = - ('a * 'a list) - [@@deriving show, eq, qcheck] - type cmd = { prog: Template.t; args: Template.t list; } [@@deriving show, eq, make, qcheck] - type t = cmd non_empty_list + type t = cmd Util.Non_empty_list.t [@@deriving show, eq, qcheck] let (~$) x = (x, []) diff --git a/lib/util.ml b/lib/util.ml index 30b8fef..985fc43 100644 --- a/lib/util.ml +++ b/lib/util.ml @@ -194,3 +194,19 @@ module URI = struct Jsont.string |> Jsont.map ~kind: "URI" ~dec: Uri.of_string ~enc: Uri.to_string end + +module Non_empty_list = struct + type 'a t = + ('a * 'a list) + [@@deriving show, eq, qcheck] + + let to_list (x, xs) = x :: xs + + let of_list = function + | [] -> None + | x :: xs -> Some (x, xs) + + let map f (x, xs) = (f x, List.map f xs) + let fold_left f acc (x, xs) = List.fold_left f acc (x :: xs) + let fold_right f acc (x, xs) = List.fold_right f acc (x :: xs) +end |
