package conex

  1. Overview
  2. Docs

String, unsigned integers, logging, collections, and more

Sets, Maps, List utils

module S : sig ... end

S is a string set.

module M : sig ... end

M is a Map which keys are strings.

val filter_map : f:('a -> 'b option) -> 'a list -> 'b list

filter_map f xs is xs', a list which contains all elements where f resulted in Some _.

Format

type 'a fmt = Stdlib.Format.formatter -> 'a -> unit

'a fmt is the signature for pretty printers.

val pp_list : 'a fmt -> 'a list fmt

pp_list pp is a pretty printer for a list (surrounded by square brackets, elements are separated by semicolon). The pp is be a pretty printer for list elements.

val str_pp : 'a fmt -> 'a -> string

str_pp pp a results in a string applying the pretty-printer to the value.

Result combinators

val (>>=) : ('a, 'b) Stdlib.result -> ('a -> ('c, 'b) Stdlib.result) -> ('c, 'b) Stdlib.result

r >>= f is f a unless r is an Error, which is propagated. Monadic bind.

val guard : bool -> 'a -> (unit, 'a) Stdlib.result

guard pred err is either Ok () (if pred holds), Error err otherwise.

val foldM : ('a -> 'b -> ('a, 'c) Stdlib.result) -> 'a -> 'b list -> ('a, 'c) Stdlib.result

foldM f a xs applies f to each element of xs, returns either Ok and the produced value, or Error.

val iterM : ('a -> (unit, 'b) Stdlib.result) -> 'a list -> (unit, 'b) Stdlib.result

iterM f xs applies f to each element of xs, returns either Ok and the produced value, or Error.

val foldS : ('a -> string -> ('a, 'c) Stdlib.result) -> 'a -> S.t -> ('a, 'c) Stdlib.result

foldS f a s applies f to each element of the set s, returns either Ok and the produced value, or Error.

val err_to_str : 'b fmt -> ('a, 'b) Stdlib.result -> ('a, string) Stdlib.result

err_to_str pp res is either Ok a or Error str where str was produced by str_pp.

String

module String : sig ... end

Some String utilities implemented here to avoid external dependencies. This is a subset of Astring.

Unsigned integers

module Uint : sig ... end

64 bit unsigned integer with explicit overflow behaviour (see Uint.succ).

module Uint_map : sig ... end

Uint_map is a Map which keys are Uint.t.

Logging

module type LOGS = sig ... end

LOGS is a subset of the Logs library, providing four log streams.

File system types

type file_type =
  1. | File
  2. | Directory

The sum type of possible file types we expect

type path = string list

A path is a list of strings

val root : path

root is the root path.

val path_to_string : path -> string

path_to_string path is String.concat "/" path.

  • raises Invalid_argument

    if path includes either "." or ".."

val string_to_path : string -> (path, string) Stdlib.result

string_to_path str is String.cuts "/" str and ensuring no empty segments, ".", or ".." be present. If str contains a leading "/", it is discarded.

val string_to_path_exn : string -> path

string_to_path_exb str is String.cuts "/" str and ensuring no empty segments, ".", or ".." be present. If str contains a leading "/", it is discarded.

  • raises Invalid_argument

    if path is invalid

val path_equal : path -> path -> bool

path_equal p p' is true if p and p' are equal.

val subpath : parent:path -> path -> bool

subpath ~parent p is true if p starts with all segments of parent.

val pp_path : path fmt

pp_path is a pretty printer for a path.

type item = file_type * string

An item is a type and its payload

Tree

module Tree : sig ... end

Tree is a simple tree datatype, edge is a string, values are 'a lists.

OCaml

Innovation. Community. Security.