Skip to content

Commit

Permalink
doc: Utils functions
Browse files Browse the repository at this point in the history
  • Loading branch information
leovalais committed Nov 26, 2018
1 parent 9602904 commit e4314fd
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/utils.mli
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,48 @@ module Operators : sig
(** [s ^* n] equals to [s ^ s ^ ... ^ s], [n] times. *)
val (^*) : string -> int -> string

(** [l @< l'] returns whether every element in [l] is also
inside [l'] (in terms of [=]). *)
val (@<) : 'a list -> 'a list -> bool

(** [l @- l'] returns the list of the elements of [l] not present
inside [l'] (in terms of [=]). *)
val (@-) : 'a list -> 'a list -> 'a list
end

(** The identity function. *)
val id : 'a -> 'a

(** [constantly x = fun _ -> x] *)
val constantly : 'a -> 'b -> 'a

(** Association lists type. *)
type ('a, 'b) alist = ('a * 'b) list

(** Continuation argument zipper.
[f (fun a -> g (fun b -> ...))] = [zipk f g (fun a b -> ...)] *)
val zipk : (('a -> 'b) -> 'c) -> (('d -> 'e) -> 'b) -> ('a -> 'd -> 'e) -> 'c

(** [zip [a1;a2;...;aN] [b1;b2;...;bM]] returns
[[(a1,b1); (a2,b2); ...; (aL,bL)]] with [L = min N M]. *)
val zip : 'a list -> 'b list -> ('a * 'b) list

(** Inverse of [zip]. *)
val unzip : ('a * 'b) list -> 'a list * 'b list

(** Groups association lists using [=] keys. For example,
[group_alists [(1, 10); (2, 20); (3, 30)] [(2, 0); (3, 1); (4, 2)]] returns
[[(2, (10, 0)); (3, (30, 1))]]. *)
val group_alists : ('a, 'b) alist -> ('a, 'c) alist -> ('a, ('b * 'c)) alist

(** [alist_of_values f [x; x'; ...]] returns [(x, f x); (x', f x'); ...]. *)
val alist_of_values : ('b -> 'a) -> 'b list -> ('a, 'b) alist

(** [check_errors [(msg, exp); ...]] evaluates in order each [exp] and raises
[Failure msg] with the [msg] of the first [exp] to return [false], if any. *)
val check_errors : (string * bool lazy_t) list -> unit

(** Converts an hash table to an association list. *)
val alist_of_hashtbl : ('a, 'b) Hashtbl.t -> ('a * 'b) list

(** [is_some x] returns whether [x] is [Some y]. *)
Expand All @@ -51,21 +65,29 @@ val is_some : 'a option -> bool
(** [is_none x] returns whether [x] is [None]. *)
val is_none : 'a option -> bool

(** Inverse of [not_foundify]. *)
val optionify : ('a -> 'b) -> ('a -> 'b option)

(** [not_foundify f] returns a wrapper of [f] that raises [Not_found]
when [f] returns [None]. *)
val not_foundify : ('a -> 'b option) -> ('a -> 'b)

(** [trim_n n s] returns [s] without its [n] first characters. *)
val trim_n : int -> string -> string

(** [trim c s] returns [s] with the trailing occurences of [c] removed. *)
val trim : char -> string -> string

(** [starts_with s s'] retruns whether [s] is a prefix of [s]. *)
val starts_with : string -> string -> bool

(** [ends_with s s'] retruns whether [s] is a suffix of [s]. *)
val ends_with : string -> string -> bool

(** Pretty prints the given columns with even horizontal spacing. *)
val sprint_two_cols : ?prefix:string -> ?sep:string -> (string * string) list -> string

(** Pretty prints the given columns with even horizontal spacing. *)
val sprint_three_cols : ?prefix:string -> ?sep:string -> (string * string * string) list -> string

(** [sorted_dir_files sort dir] returns the list of the files inside [dir]
Expand Down

0 comments on commit e4314fd

Please sign in to comment.