-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.mli
49 lines (32 loc) · 1.28 KB
/
util.mli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(** Various utility functions *)
(** unwraps an option *)
val get_option : 'a option -> 'a
(** map a function over an option *)
val map_option : ('a -> 'b) -> 'a option -> 'b option
(** Return true for Some x *)
val is_some: 'a option -> bool
(** Return true for None *)
val is_none: 'a option -> bool
(** [pow a b] returns a to the bth power *)
val pow : int -> int -> int
(** [replace arr i f] replaces arr.(i) with f(arr.(i)) *)
val replace : 'a array -> int -> ('a -> 'a) -> unit
(** return true if the argument is a power of two *)
val power_of_two : int -> bool
(** [log a b] returns log base a of b *)
val log : int -> int -> int
(** searches for a string within another string *)
val contains : within:string -> string -> bool
(** Strip spaces from the front and back *)
val strip_spaces : string -> string
(** Head of a list, or assertion failure *)
val hd_exn : 'a list -> 'a
(** [pick list partial to_string] returns the element of list that
matches partial. to_string is called to get the string representation
of each member of list. *)
val pick : 'a list -> string -> ('a -> string) -> 'a
(** The identity function *)
val id : 'a -> 'a
(** First filter a list, then map over it *)
val filter_then_map :
mapf:('a -> 'b) -> filterf:('a -> bool) -> 'a list -> 'b list