package dolmen

  1. Overview
  2. Docs

Module Dolmen_std.MiscSource

Comparison helpers

Sourceval (<?>) : int -> (('a -> 'a -> int) * 'a * 'a) -> int

Composition of comparison functions.

Sourceval lexicographic : ('a -> 'a -> int) -> 'a list -> 'a list -> int

Lexicogrphic comparison on lsits.

Hash helpers

Sourceval hash_int : int -> int
Sourceval hash_string : string -> int
Sourceval hash_list : ('a -> int) -> 'a list -> int
Sourceval hash2 : int -> int -> int
Sourceval hash3 : int -> int -> int -> int
Sourceval hash4 : int -> int -> int -> int -> int

Hash combinators.

Misc functions

Sourceval get_extension : string -> string

Returns the extension of a file, i.e the shortest suffix containing the character '.'. Returns an empty string if such a suffix does not exists.

Sourceval split_on_char : char -> string -> string list

Split on characters in a string (see Stdlib's split_on_char).

Sourceval replicate : int -> 'a -> 'a list

Returns a list with n times the given value. Returns an empty list if n

Sourceval opt_map : 'a option -> ('a -> 'b) -> 'b option

Map on option.

Sourceval opt_bind : 'a option -> ('a -> 'b option) -> 'b option

Bind on option.

Sourceval string_for_all : ?start:int -> (char -> bool) -> string -> bool

Equivalent to String.for_all (which is only available on ocaml >= 4.10)

Sourceval string_unicode_map : ?encoding_from:Uutf.decoder_encoding -> ?encoding_to:Uutf.encoding -> (int -> Uchar.t option -> Uchar.t list) -> string -> string

Printing helpers

Sourceval pp_opt : ?none:string -> (Buffer.t -> 'a -> unit) -> Buffer.t -> 'a option -> unit

Print an option

Sourceval pp_list : pp_sep:(Buffer.t -> 'a -> unit) -> sep:'a -> pp:(Buffer.t -> 'b -> unit) -> Buffer.t -> 'b list -> unit

Print a list with separator into a buffer

Sourceval print_opt : ?none:string -> (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a option -> unit

Print an option.

Sourceval print_list : print_sep:(Format.formatter -> 'a -> unit) -> sep:'a -> print:(Format.formatter -> 'b -> unit) -> Format.formatter -> 'b list -> unit

Print a list with separator into a buffer

Iteration helpers

Sourceval foldn : int -> ('a -> 'a) -> 'a -> 'a

Applies the given function n times.

Sourceval list_concat_map : ('a -> 'b list) -> 'a list -> 'b list

Same as

ist.concat_map

(which is not available on ocaml.4.08).

Sourceval list_map_sharing : ('a -> 'a) -> 'a list -> 'a list

Same as `List.map` but if all elements of the new lists are physically equal to the ones from the original list, then the original list is returned.

Sourceval list_partition_map : ('a -> [ `Left of 'b | `Right of 'c ]) -> 'a list -> 'b list * 'c list

Re-implementation of List.partition_map (which was added in ocaml 4.12).

String helpers

Sourceval exists_in_string : (char -> bool) -> string -> bool

Simialr to stdlib's String.exists, but without require recent enough versions of the compiler.

Lexbuf helpers

Sourceval filename_of_input : [ `Stdin | `File of string | `Contents of string * string ] -> string

Filename string of an input.

Sourceval filename_of_input_source : [ `Stdin | `File of string | `Raw of string * string ] -> string

Filename string of an input source.

Sourceval mk_lexbuf : [ `Stdin | `File of string | `Contents of string * string ] -> Lexing.lexbuf * (unit -> unit)

Returns the lexbuf associetd with the given file or stdin, with the correct filename, together with a function to close the associated file descriptor. The `Contents constructor expect first a name for the input stream (to report errors), and then a string with the actual contents to be parsed.

Sourceval lex_string : (Lexing.lexbuf -> 'a) -> string -> 'a

Tries and parse the string with the given lexer rule.