From: Richard W.M. Jones Date: Thu, 9 Jan 2020 18:11:26 +0000 (+0000) Subject: utils: Add unique () function. X-Git-Tag: v'0.2'~53 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=0aead2922062dc8a4e7dc88fe7776f92ac6c232a;p=goals.git utils: Add unique () function. --- diff --git a/src/utils.ml b/src/utils.ml index 50adfb4..3d1b0c5 100644 --- a/src/utils.ml +++ b/src/utils.ml @@ -24,6 +24,8 @@ let failwithf fs = ksprintf failwith fs let (//) = Filename.concat let is_directory d = try Sys.is_directory d with Sys_error _ -> false +let unique = let i = ref 0 in fun () -> incr i; !i + (* From OCaml 4.08 sources. We can remove this when we can * depend on min OCaml 4.08. *) diff --git a/src/utils.mli b/src/utils.mli index 8edfaae..1979a34 100644 --- a/src/utils.mli +++ b/src/utils.mli @@ -26,6 +26,9 @@ val (//) : string -> string -> string val is_directory : string -> bool (** Return true iff parameter is a directory. *) +val unique : unit -> int +(** Returns a unique number each time called. *) + val filter_map : ('a -> 'b option) -> 'a list -> 'b list (** [filter_map f l] applies [f] to every element of [l], filters out the [None] elements and returns the list of the arguments of