summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorยท๐‘‘๐‘ด๐‘•๐‘‘๐‘ฉ๐‘ค2025-12-11 10:35:34 +0000
committerยท๐‘‘๐‘ด๐‘•๐‘‘๐‘ฉ๐‘ค2025-12-11 10:35:34 +0000
commitfe167ebb24c02486b80ccb8b8684a121dae00d60 (patch)
tree13a7fcfefbc87ffe3bfd78be357ef47c5a874581
parent5fc560944760ddcd38399a39f8ddd275cd4b7d2b (diff)
downloadnixtaml-fe167ebb24c02486b80ccb8b8684a121dae00d60.tar
nixtaml-fe167ebb24c02486b80ccb8b8684a121dae00d60.tar.gz
nixtaml-fe167ebb24c02486b80ccb8b8684a121dae00d60.tar.bz2
nixtaml-fe167ebb24c02486b80ccb8b8684a121dae00d60.tar.lz
nixtaml-fe167ebb24c02486b80ccb8b8684a121dae00d60.tar.xz
nixtaml-fe167ebb24c02486b80ccb8b8684a121dae00d60.tar.zst
nixtaml-fe167ebb24c02486b80ccb8b8684a121dae00d60.zip
move Non_empty_list to Utils
-rw-r--r--lib/input.ml6
-rw-r--r--lib/util.ml16
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