Library
Module
Module type
Parameter
Class
Class type
Base functions.
Same as Lwt.both
, but immediately propagate exceptions.
More precisely, if one of the two promises is rejected or canceled, cancel the other promise and reject the resulting promise immediately with the original exception.
val return : 'a -> 'a Lwt.t
Same as Lwt.return
.
val unit : unit Lwt.t
Same as Lwt.return_unit
.
val none : 'a option Lwt.t
Same as Lwt.return_none
.
val some : 'a -> 'a option Lwt.t
Same as Lwt.return_some
.
Get the value of an option that must not be None
.
Usage: mandatory name option
name
is used in the error message if option
is None
.
Make a list of all integers between two integers.
If the first argument a
is greater than the second argument b
, return the empty list. Otherwise, returns the list a; ...; b
.
Backport of List.find_map
from OCaml 4.10.
take n l
returns the first n
elements of l
if longer than n
, else l
itself.
drop n l
removes the first n
elements of l
if longer than n
, else the empty list. Raise invalid_arg
if n
is negative.
Split a list based on a predicate.
span f l
returns a pair of lists (l1, l2)
, where l1
is the longest prefix of l
that satisfies the predicate f
, and l2
is the rest of the list. The order of the elements in the input list is preserved such that l = l1 @ l2
.
val rex : ?opts:Re.Perl.opt list -> string -> rex
Compile a regular expression using Perl syntax.
val rexf :
?opts:Re.Perl.opt list ->
('a, unit, string, rex) Stdlib.format4 ->
'a
Same as rex @@ sf ...
.
val show_rex : rex -> string
Convert a regular expression to a string using Perl syntax.
val (=~) : string -> rex -> bool
Test whether a string matches a regular expression.
Example: "number 1234 matches" =~ rex "\\d+"
val (=~!) : string -> rex -> bool
Negation of =~
.
val (=~*) : string -> rex -> string option
Match a regular expression with one capture group.
val (=~**) : string -> rex -> (string * string) option
Match a regular expression with two capture groups.
val (=~***) : string -> rex -> (string * string * string) option
Match a regular expression with three capture groups.
val (=~****) : string -> rex -> (string * string * string * string) option
Match a regular expression with four capture groups.
val matches : string -> rex -> string list
Match a regular expression with one capture group and return all results.
val replace_string :
?pos:int ->
?len:int ->
?all:bool ->
rex ->
by:string ->
string ->
string
replace_string ~all rex ~by s
iterates on s
, and replaces every occurrence of rex
with by
. If all = false
, then only the first occurrence of rex
is replaced.
Open file, use function to write output then close the output. In case of error while writing, the channel is closed before raising the exception
Open file, use function to read input then close the input. In case of error while reading, the channel is closed before raising the exception *
Write a string into a file, overwriting the file if it already exists.
Usage: write_file filename ~contents
module String_set : sig ... end