diff --git a/dev/containers-data/CCBV/index.html b/dev/containers-data/CCBV/index.html index 3a0ef276..35df3f70 100644 --- a/dev/containers-data/CCBV/index.html +++ b/dev/containers-data/CCBV/index.html @@ -1,2 +1,2 @@ -CCBV (containers-data.CCBV)

Module CCBV

Imperative Bitvectors

BREAKING CHANGES since 1.2: size is now stored along with the bitvector. Some functions have a new signature.

The size of the bitvector used to be rounded up to the multiple of 30 or 62. In other words some functions such as iter would iterate on more bits than what was originally asked for. This is not the case anymore.

type t

A resizable bitvector

val empty : unit -> t

Empty bitvector.

val create : size:int -> bool -> t

Create a bitvector of given size, with given default value.

val copy : t -> t

Copy of bitvector.

val cardinal : t -> int

Number of bits set to one, seen as a set of bits.

val length : t -> int

Size of underlying bitvector. This is not related to the underlying implementation. Changed at 1.2

val capacity : t -> int

The number of bits this bitvector can store without resizing.

since
1.2
val resize : t -> int -> unit

Resize the BV so that it has the specified length. This can grow or shrink the underlying bitvector.

raises Invalid_arg

on negative sizes.

val is_empty : t -> bool

Are there any true bits?

val set : t -> int -> unit

Set i-th bit, extending the bitvector if needed.

val get : t -> int -> bool

Is the i-th bit true? Return false if the index is too high.

val reset : t -> int -> unit

Set i-th bit to 0, extending the bitvector if needed.

val flip : t -> int -> unit

Flip i-th bit, extending the bitvector if needed.

val clear : t -> unit

Set every bit to 0.

val iter : t -> (int -> bool -> unit) -> unit

Iterate on all bits.

val iter_true : t -> (int -> unit) -> unit

Iterate on bits set to 1.

val to_list : t -> int list

List of indexes that are true.

val to_sorted_list : t -> int list

Same as to_list, but also guarantees the list is sorted in increasing order.

val of_list : int list -> t

From a list of true bits.

The bits are interpreted as indices into the returned bitvector, so the final bitvector bv will have length bv equal to 1 more than max of list indices.

val first : t -> int option

First set bit, or return None. Changed type at 1.2

val first_exn : t -> int

First set bit, or

raises Not_found

if all bits are 0.

since
1.2
val filter : t -> (int -> bool) -> unit

filter bv p only keeps the true bits of bv whose index satisfies p index.

val negate_self : t -> unit

negate_self t flips all of the bits in t.

since
1.2
val negate : t -> t

negate t returns a copy of t with all of the bits flipped.

val union_into : into:t -> t -> unit

union_into ~into bv sets into to the union of itself and bv. Also updates the length of into to be at least length bv.

val inter_into : into:t -> t -> unit

inter_into ~into bv sets into to the intersection of itself and bv. Also updates the length of into to be at most length bv.

val union : t -> t -> t

union bv1 bv2 returns the union of the two sets.

val inter : t -> t -> t

inter bv1 bv2 returns the intersection of the two sets.

val diff_into : into:t -> t -> unit

diff_into ~into t modifies into with only the bits set but not in t.

since
1.2
val diff : t -> t -> t

diff t1 t2 returns those bits found in t1 but not in t2.

since
1.2
val select : t -> 'a array -> 'a list

select arr bv selects the elements of arr whose index corresponds to a true bit in bv. If bv is too short, elements of arr with too high an index cannot be selected and are therefore not selected.

val selecti : t -> 'a array -> ('a * int) list

Same as select, but selected elements are paired with their indexes.

val equal : t -> t -> bool

Bitwise comparison, including the size (equal a b implies length a=length b).

since
NEXT_RELEASE
type 'a iter = ('a -> unit) -> unit
val to_iter : t -> int iter
val of_iter : int iter -> t
val pp : Stdlib.Format.formatter -> t -> unit

Print the bitvector as a string of bits.

since
0.13
\ No newline at end of file +CCBV (containers-data.CCBV)

Module CCBV

Imperative Bitvectors

BREAKING CHANGES since 1.2: size is now stored along with the bitvector. Some functions have a new signature.

The size of the bitvector used to be rounded up to the multiple of 30 or 62. In other words some functions such as iter would iterate on more bits than what was originally asked for. This is not the case anymore.

type t

A resizable bitvector

val empty : unit -> t

Empty bitvector.

val create : size:int -> bool -> t

Create a bitvector of given size, with given default value.

val copy : t -> t

Copy of bitvector.

val cardinal : t -> int

Number of bits set to one, seen as a set of bits.

val length : t -> int

Size of underlying bitvector. This is not related to the underlying implementation. Changed at 1.2

val capacity : t -> int

The number of bits this bitvector can store without resizing.

since
1.2
val resize : t -> int -> unit

Resize the BV so that it has the specified length. This can grow or shrink the underlying bitvector.

raises Invalid_arg

on negative sizes.

val is_empty : t -> bool

Are there any true bits?

val set : t -> int -> unit

Set i-th bit, extending the bitvector if needed.

val get : t -> int -> bool

Is the i-th bit true? Return false if the index is too high.

val reset : t -> int -> unit

Set i-th bit to 0, extending the bitvector if needed.

val flip : t -> int -> unit

Flip i-th bit, extending the bitvector if needed.

val clear : t -> unit

Set every bit to 0.

val iter : t -> (int -> bool -> unit) -> unit

Iterate on all bits.

val iter_true : t -> (int -> unit) -> unit

Iterate on bits set to 1.

val to_list : t -> int list

List of indexes that are true.

val to_sorted_list : t -> int list

Same as to_list, but also guarantees the list is sorted in increasing order.

val of_list : int list -> t

From a list of true bits.

The bits are interpreted as indices into the returned bitvector, so the final bitvector bv will have length bv equal to 1 more than max of list indices.

val first : t -> int option

First set bit, or return None. Changed type at 1.2

val first_exn : t -> int

First set bit, or

raises Not_found

if all bits are 0.

since
1.2
val filter : t -> (int -> bool) -> unit

filter bv p only keeps the true bits of bv whose index satisfies p index.

val negate_self : t -> unit

negate_self t flips all of the bits in t.

since
1.2
val negate : t -> t

negate t returns a copy of t with all of the bits flipped.

val union_into : into:t -> t -> unit

union_into ~into bv sets into to the union of itself and bv. Also updates the length of into to be at least length bv.

val inter_into : into:t -> t -> unit

inter_into ~into bv sets into to the intersection of itself and bv. Also updates the length of into to be at most length bv.

val union : t -> t -> t

union bv1 bv2 returns the union of the two sets.

val inter : t -> t -> t

inter bv1 bv2 returns the intersection of the two sets.

val diff_into : into:t -> t -> unit

diff_into ~into t modifies into with only the bits set but not in t.

since
1.2
val diff : t -> t -> t

diff t1 t2 returns those bits found in t1 but not in t2.

since
1.2
val select : t -> 'a array -> 'a list

select arr bv selects the elements of arr whose index corresponds to a true bit in bv. If bv is too short, elements of arr with too high an index cannot be selected and are therefore not selected.

val selecti : t -> 'a array -> ('a * int) list

Same as select, but selected elements are paired with their indexes.

val equal : t -> t -> bool

Bitwise comparison, including the size (equal a b implies length a=length b).

since
3.5
type 'a iter = ('a -> unit) -> unit
val to_iter : t -> int iter
val of_iter : int iter -> t
val pp : Stdlib.Format.formatter -> t -> unit

Print the bitvector as a string of bits.

since
0.13
\ No newline at end of file diff --git a/dev/containers/CCFormat/ANSI_codes/index.html b/dev/containers/CCFormat/ANSI_codes/index.html index edade891..f2f865ad 100644 --- a/dev/containers/CCFormat/ANSI_codes/index.html +++ b/dev/containers/CCFormat/ANSI_codes/index.html @@ -1,3 +1,3 @@ -ANSI_codes (containers.CCFormat.ANSI_codes)

Module CCFormat.ANSI_codes

ANSI escape codes. This contains lower level functions for them.

since
NEXT_RELEASE
type color = [
| `Black
| `Red
| `Yellow
| `Green
| `Blue
| `Magenta
| `Cyan
| `White
]

An ANSI color

type style = [
| `FG of color

foreground

| `BG of color

background

| `Bold
| `Reset
]

A style. Styles can be composed in a list.

val clear_line : string

clear_line is an escape code to clear the current line. It is very useful for progress bars; for example:

let pp_progress i =
+ANSI_codes (containers.CCFormat.ANSI_codes)

Module CCFormat.ANSI_codes

ANSI escape codes. This contains lower level functions for them.

since
3.5
type color = [
| `Black
| `Red
| `Yellow
| `Green
| `Blue
| `Magenta
| `Cyan
| `White
]

An ANSI color

type style = [
| `FG of color

foreground

| `BG of color

background

| `Bold
| `Reset
]

A style. Styles can be composed in a list.

val clear_line : string

clear_line is an escape code to clear the current line. It is very useful for progress bars; for example:

let pp_progress i =
   Printf.printf "%sprogress at %d%!" ANSI_codes.clear_line i

if called repeatedly this will print successive progress messages on a single line.

val reset : string

The escape code to reset style (colors, bold, etc.)

val string_of_style : style -> string

string_of_style st is an escape code to set the current style to st. It can be printed as is on any output that is a compatible terminal.

val string_of_style_list : style list -> string

string_of_style_list styles is an escape code for multiple styles at once. For example string_of_style_list ANSI_codes.([`FG `Red; `BG `Green; `Bold]) is a very shiny style.

\ No newline at end of file diff --git a/dev/containers/CCFormat/index.html b/dev/containers/CCFormat/index.html index 21543479..78735a70 100644 --- a/dev/containers/CCFormat/index.html +++ b/dev/containers/CCFormat/index.html @@ -1,5 +1,5 @@ -CCFormat (containers.CCFormat)

Module CCFormat

Helpers for Format

since
0.8
type 'a iter = ('a -> unit) -> unit

Documentation for the standard Format module

include module type of sig ... end
type formatter = Stdlib__format.formatter
val pp_open_box : formatter -> int -> unit
val open_box : int -> unit
val pp_close_box : formatter -> unit -> unit
val close_box : unit -> unit
val pp_open_hbox : formatter -> unit -> unit
val open_hbox : unit -> unit
val pp_open_vbox : formatter -> int -> unit
val open_vbox : int -> unit
val pp_open_hvbox : formatter -> int -> unit
val open_hvbox : int -> unit
val pp_open_hovbox : formatter -> int -> unit
val open_hovbox : int -> unit
val pp_print_string : formatter -> string -> unit
val print_string : string -> unit
val pp_print_as : formatter -> int -> string -> unit
val print_as : int -> string -> unit
val pp_print_int : formatter -> int -> unit
val print_int : int -> unit
val pp_print_float : formatter -> float -> unit
val print_float : float -> unit
val pp_print_char : formatter -> char -> unit
val print_char : char -> unit
val pp_print_bool : formatter -> bool -> unit
val print_bool : bool -> unit
val pp_print_space : formatter -> unit -> unit
val print_space : unit -> unit
val pp_print_cut : formatter -> unit -> unit
val print_cut : unit -> unit
val pp_print_break : formatter -> int -> int -> unit
val print_break : int -> int -> unit
val pp_print_custom_break : formatter -> fits:(string * int * string) -> breaks:(string * int * string) -> unit
val pp_force_newline : formatter -> unit -> unit
val force_newline : unit -> unit
val pp_print_if_newline : formatter -> unit -> unit
val print_if_newline : unit -> unit
val pp_print_flush : formatter -> unit -> unit
val print_flush : unit -> unit
val pp_print_newline : formatter -> unit -> unit
val print_newline : unit -> unit
val pp_set_margin : formatter -> int -> unit
val set_margin : int -> unit
val pp_get_margin : formatter -> unit -> int
val get_margin : unit -> int
val pp_set_max_indent : formatter -> int -> unit
val set_max_indent : int -> unit
val pp_get_max_indent : formatter -> unit -> int
val get_max_indent : unit -> int
type geometry = Stdlib__format.geometry = {
max_indent : int;
margin : int;
}
val check_geometry : geometry -> bool
val pp_set_geometry : formatter -> max_indent:int -> margin:int -> unit
val set_geometry : max_indent:int -> margin:int -> unit
val pp_safe_set_geometry : formatter -> max_indent:int -> margin:int -> unit
val safe_set_geometry : max_indent:int -> margin:int -> unit
val pp_update_geometry : formatter -> (geometry -> geometry) -> unit
val update_geometry : (geometry -> geometry) -> unit
val pp_get_geometry : formatter -> unit -> geometry
val get_geometry : unit -> geometry
val pp_set_max_boxes : formatter -> int -> unit
val set_max_boxes : int -> unit
val pp_get_max_boxes : formatter -> unit -> int
val get_max_boxes : unit -> int
val pp_over_max_boxes : formatter -> unit -> bool
val over_max_boxes : unit -> bool
val pp_open_tbox : formatter -> unit -> unit
val open_tbox : unit -> unit
val pp_close_tbox : formatter -> unit -> unit
val close_tbox : unit -> unit
val pp_set_tab : formatter -> unit -> unit
val set_tab : unit -> unit
val pp_print_tab : formatter -> unit -> unit
val print_tab : unit -> unit
val pp_print_tbreak : formatter -> int -> int -> unit
val print_tbreak : int -> int -> unit
val pp_set_ellipsis_text : formatter -> string -> unit
val set_ellipsis_text : string -> unit
val pp_get_ellipsis_text : formatter -> unit -> string
val get_ellipsis_text : unit -> string
type stag = Stdlib__format.stag = ..
type tag = string
type stag += String_tag of tag
val pp_open_stag : formatter -> stag -> unit
val open_stag : stag -> unit
val pp_close_stag : formatter -> unit -> unit
val close_stag : unit -> unit
val pp_set_tags : formatter -> bool -> unit
val set_tags : bool -> unit
val pp_set_print_tags : formatter -> bool -> unit
val set_print_tags : bool -> unit
val pp_set_mark_tags : formatter -> bool -> unit
val set_mark_tags : bool -> unit
val pp_get_print_tags : formatter -> unit -> bool
val get_print_tags : unit -> bool
val pp_get_mark_tags : formatter -> unit -> bool
val get_mark_tags : unit -> bool
val pp_set_formatter_out_channel : formatter -> Stdlib.out_channel -> unit
val set_formatter_out_channel : Stdlib.out_channel -> unit
val pp_set_formatter_output_functions : formatter -> (string -> int -> int -> unit) -> (unit -> unit) -> unit
val set_formatter_output_functions : (string -> int -> int -> unit) -> (unit -> unit) -> unit
val pp_get_formatter_output_functions : formatter -> unit -> (string -> int -> int -> unit) * (unit -> unit)
val get_formatter_output_functions : unit -> (string -> int -> int -> unit) * (unit -> unit)
type formatter_out_functions = Stdlib__format.formatter_out_functions = {
out_string : string -> int -> int -> unit;
out_flush : unit -> unit;
out_newline : unit -> unit;
out_spaces : int -> unit;
out_indent : int -> unit;
}
val pp_set_formatter_out_functions : formatter -> formatter_out_functions -> unit
val set_formatter_out_functions : formatter_out_functions -> unit
val pp_get_formatter_out_functions : formatter -> unit -> formatter_out_functions
val get_formatter_out_functions : unit -> formatter_out_functions
type formatter_stag_functions = Stdlib__format.formatter_stag_functions = {
mark_open_stag : stag -> string;
mark_close_stag : stag -> string;
print_open_stag : stag -> unit;
print_close_stag : stag -> unit;
}
val pp_set_formatter_stag_functions : formatter -> formatter_stag_functions -> unit
val set_formatter_stag_functions : formatter_stag_functions -> unit
val pp_get_formatter_stag_functions : formatter -> unit -> formatter_stag_functions
val get_formatter_stag_functions : unit -> formatter_stag_functions
val formatter_of_out_channel : Stdlib.out_channel -> formatter
val std_formatter : formatter
val err_formatter : formatter
val formatter_of_buffer : Stdlib.Buffer.t -> formatter
val stdbuf : Stdlib.Buffer.t
val str_formatter : formatter
val flush_str_formatter : unit -> string
val make_formatter : (string -> int -> int -> unit) -> (unit -> unit) -> formatter
val formatter_of_out_functions : formatter_out_functions -> formatter
type symbolic_output_item = Stdlib__format.symbolic_output_item =
| Output_flush
| Output_newline
| Output_string of string
| Output_spaces of int
| Output_indent of int
type symbolic_output_buffer = Stdlib__format.symbolic_output_buffer
val make_symbolic_output_buffer : unit -> symbolic_output_buffer
val clear_symbolic_output_buffer : symbolic_output_buffer -> unit
val get_symbolic_output_buffer : symbolic_output_buffer -> symbolic_output_item list
val flush_symbolic_output_buffer : symbolic_output_buffer -> symbolic_output_item list
val add_symbolic_output_item : symbolic_output_buffer -> symbolic_output_item -> unit
val formatter_of_symbolic_output_buffer : symbolic_output_buffer -> formatter
val pp_print_list : ?⁠pp_sep:(formatter -> unit -> unit) -> (formatter -> 'a -> unit) -> formatter -> 'a list -> unit
val pp_print_seq : ?⁠pp_sep:(formatter -> unit -> unit) -> (formatter -> 'a -> unit) -> formatter -> 'a Stdlib.Seq.t -> unit
val pp_print_text : formatter -> string -> unit
val pp_print_option : ?⁠none:(formatter -> unit -> unit) -> (formatter -> 'a -> unit) -> formatter -> 'a option -> unit
val pp_print_result : ok:(formatter -> 'a -> unit) -> error:(formatter -> 'e -> unit) -> formatter -> ('a'e) Stdlib.result -> unit
val fprintf : formatter -> ('aformatter, unit) Stdlib.format -> 'a
val printf : ('aformatter, unit) Stdlib.format -> 'a
val eprintf : ('aformatter, unit) Stdlib.format -> 'a
val sprintf : ('a, unit, string) Stdlib.format -> 'a
val asprintf : ('aformatter, unit, string) Stdlib.format4 -> 'a
val dprintf : ('aformatter, unit, formatter -> unit) Stdlib.format4 -> 'a
val ifprintf : formatter -> ('aformatter, unit) Stdlib.format -> 'a
val kfprintf : (formatter -> 'a) -> formatter -> ('bformatter, unit, 'a) Stdlib.format4 -> 'b
val kdprintf : ((formatter -> unit) -> 'a) -> ('bformatter, unit, 'a) Stdlib.format4 -> 'b
val ikfprintf : (formatter -> 'a) -> formatter -> ('bformatter, unit, 'a) Stdlib.format4 -> 'b
val ksprintf : (string -> 'a) -> ('b, unit, string, 'a) Stdlib.format4 -> 'b
val kasprintf : (string -> 'a) -> ('bformatter, unit, 'a) Stdlib.format4 -> 'b
val bprintf : Stdlib.Buffer.t -> ('aformatter, unit) Stdlib.format -> 'a
val kprintf : (string -> 'a) -> ('b, unit, string, 'a) Stdlib.format4 -> 'b
val set_all_formatter_output_functions : out:(string -> int -> int -> unit) -> flush:(unit -> unit) -> newline:(unit -> unit) -> spaces:(int -> unit) -> unit
val get_all_formatter_output_functions : unit -> (string -> int -> int -> unit) * (unit -> unit) * (unit -> unit) * (int -> unit)
val pp_set_all_formatter_output_functions : formatter -> out:(string -> int -> int -> unit) -> flush:(unit -> unit) -> newline:(unit -> unit) -> spaces:(int -> unit) -> unit
val pp_get_all_formatter_output_functions : formatter -> unit -> (string -> int -> int -> unit) * (unit -> unit) * (unit -> unit) * (int -> unit)
val pp_open_tag : formatter -> tag -> unit
val open_tag : tag -> unit
val pp_close_tag : formatter -> unit -> unit
val close_tag : unit -> unit
type formatter_tag_functions = Stdlib__format.formatter_tag_functions = {
mark_open_tag : tag -> string;
mark_close_tag : tag -> string;
print_open_tag : tag -> unit;
print_close_tag : tag -> unit;
}
val pp_set_formatter_tag_functions : formatter -> formatter_tag_functions -> unit
val set_formatter_tag_functions : formatter_tag_functions -> unit
val pp_get_formatter_tag_functions : formatter -> unit -> formatter_tag_functions
val get_formatter_tag_functions : unit -> formatter_tag_functions
type t = Stdlib.Format.formatter
type -'a printer = t -> 'a -> unit

Combinators

val silent : 'a printer

Prints nothing.

val unit : unit printer

Prints "()".

val int : int printer
val string : string printer
val bool : bool printer
val float3 : float printer
val float : float printer
val exn : exn printer

Printer using Printexc.to_string.

since
3.0
val space : unit printer

Alias to pp_print_space.

since
3.2
val cut : unit printer

Alias to pp_print_cut.

since
3.2
val break : (int * int) printer

Tuple-ized printer form of pp_print_break.

since
3.2
val newline : unit printer

Force newline (see Format.pp_force_newline).

since
1.2
val substring : (string * int * int) printer

substring (s,i,len) prints the substring (s,i,len), where i is the offset in s and len the number of bytes in the substring.

raises Invalid_argument

if the triple (s,i,len) does not describe a proper substring.

since
1.2
val text : string printer

Print string, but replacing spaces with breaks and newlines with newline. See pp_print_text on recent versions of OCaml.

since
1.2
val string_lines : string printer

string_lines out s prints s with all newlines ('\n') replaced by a cut, in a vertical box. It does NOT insert breakable spaces in place of spaces, unlike text. This means an already formatted string can be displayed inside another formatter without mangling the indentation.

since
3.3
val char : char printer
since
0.14
val int32 : int32 printer
since
0.14
val int64 : int64 printer
since
0.14
val nativeint : nativeint printer
since
0.14
val flush : unit printer

Alias to Format.pp_print_flush.

since
1.2
val string_quoted : string printer

Similar to CCString.print.

since
0.14
val list : ?⁠sep:unit printer -> 'a printer -> 'a list printer
val array : ?⁠sep:unit printer -> 'a printer -> 'a array printer
val arrayi : ?⁠sep:unit printer -> (int * 'a) printer -> 'a array printer
val seq : ?⁠sep:unit printer -> 'a printer -> 'a Stdlib.Seq.t printer
val iter : ?⁠sep:unit printer -> 'a printer -> 'a iter printer
val opt : 'a printer -> 'a option printer

opt pp prints options as follows:

  • Some x will become "some foo" if pp x ---> "foo".
  • None will become "none".
val pair : ?⁠sep:unit printer -> 'a printer -> 'b printer -> ('a * 'b) printer
val triple : ?⁠sep:unit printer -> 'a printer -> 'b printer -> 'c printer -> ('a * 'b * 'c) printer
val quad : ?⁠sep:unit printer -> 'a printer -> 'b printer -> 'c printer -> 'd printer -> ('a * 'b * 'c * 'd) printer
val append : unit printer -> unit printer -> unit printer

append ppa ppb first prints ppa (), then prints ppb ().

since
3.2
val append_l : unit printer list -> unit printer

append_l pps runs the printers in pps sequentially.

since
3.2
val within : string -> string -> 'a printer -> 'a printer

within a b p wraps p inside the strings a and b. Convenient, for instances, for brackets, parenthesis, quotes, etc.

since
0.17
val map : ('a -> 'b) -> 'b printer -> 'a printer
val vbox : ?⁠i:int -> 'a printer -> 'a printer

Wrap the printer in a vertical box.

parameter i

level of indentation within the box (default 0).

since
0.16
val hvbox : ?⁠i:int -> 'a printer -> 'a printer

Wrap the printer in a horizontal/vertical box.

parameter i

level of indentation within the box (default 0).

since
0.16
val hovbox : ?⁠i:int -> 'a printer -> 'a printer

Wrap the printer in a horizontal or vertical box.

parameter i

level of indentation within the box (default 0).

since
0.16
val hbox : 'a printer -> 'a printer

Wrap the printer in an horizontal box.

since
0.16
val return : ('a__'a) Stdlib.format4 -> unit printer

return "some_format_string" takes a argument-less format string and returns a printer actionable by (). Examples:

  • return ",@ "
  • return "@{<Red>and then@}@,"
  • return "@[<v>a@ b@]"
since
1.0
val of_to_string : ('a -> string) -> 'a printer

of_to_string f converts its input to a string using f, then prints the string.

since
1.0
val const : 'a printer -> 'a -> unit printer

const pp x is a unit printer that uses pp on x.

since
1.0
val some : 'a printer -> 'a option printer

some pp will print options as follows:

  • Some x is printed using pp on x
  • None is not printed at all
since
1.0
val const_string : string -> 'a printer

const_string s is a printer that ignores its input and always prints s.

since
NEXT_RELEASE
val opaque : 'a printer

opaque is const_string "opaque". The exact string used is not stable.

since
NEXT_RELEASE
val lazy_force : 'a printer -> 'a lazy_t printer

lazy_force pp out x forces x and prints the result with pp.

since
2.0
val lazy_or : ?⁠default:unit printer -> 'a printer -> 'a lazy_t printer

lazy_or ?default pp out x prints default if x is not evaluated yet, or uses pp otherwise.

since
2.0

ANSI codes

Use ANSI escape codes https://en.wikipedia.org/wiki/ANSI_escape_code to put some colors on the terminal.

This uses tags in format strings to specify the style. Current styles are the following:

  • "reset" resets style
  • "black"
  • "red"
  • "green"
  • "yellow"
  • "blue"
  • "magenta"
  • "cyan"
  • "white"
  • "bold" bold font
  • "Black" bold black
  • "Red" bold red
  • "Green" bold green
  • "Yellow" bold yellow
  • "Blue" bold blue
  • "Magenta" bold magenta
  • "Cyan" bold cyan
  • "White" bold white

Example:

set_color_default true;;
+CCFormat (containers.CCFormat)

Module CCFormat

Helpers for Format

since
0.8
type 'a iter = ('a -> unit) -> unit

Documentation for the standard Format module

include module type of sig ... end
type formatter = Stdlib__format.formatter
val pp_open_box : formatter -> int -> unit
val open_box : int -> unit
val pp_close_box : formatter -> unit -> unit
val close_box : unit -> unit
val pp_open_hbox : formatter -> unit -> unit
val open_hbox : unit -> unit
val pp_open_vbox : formatter -> int -> unit
val open_vbox : int -> unit
val pp_open_hvbox : formatter -> int -> unit
val open_hvbox : int -> unit
val pp_open_hovbox : formatter -> int -> unit
val open_hovbox : int -> unit
val pp_print_string : formatter -> string -> unit
val print_string : string -> unit
val pp_print_as : formatter -> int -> string -> unit
val print_as : int -> string -> unit
val pp_print_int : formatter -> int -> unit
val print_int : int -> unit
val pp_print_float : formatter -> float -> unit
val print_float : float -> unit
val pp_print_char : formatter -> char -> unit
val print_char : char -> unit
val pp_print_bool : formatter -> bool -> unit
val print_bool : bool -> unit
val pp_print_space : formatter -> unit -> unit
val print_space : unit -> unit
val pp_print_cut : formatter -> unit -> unit
val print_cut : unit -> unit
val pp_print_break : formatter -> int -> int -> unit
val print_break : int -> int -> unit
val pp_print_custom_break : formatter -> fits:(string * int * string) -> breaks:(string * int * string) -> unit
val pp_force_newline : formatter -> unit -> unit
val force_newline : unit -> unit
val pp_print_if_newline : formatter -> unit -> unit
val print_if_newline : unit -> unit
val pp_print_flush : formatter -> unit -> unit
val print_flush : unit -> unit
val pp_print_newline : formatter -> unit -> unit
val print_newline : unit -> unit
val pp_set_margin : formatter -> int -> unit
val set_margin : int -> unit
val pp_get_margin : formatter -> unit -> int
val get_margin : unit -> int
val pp_set_max_indent : formatter -> int -> unit
val set_max_indent : int -> unit
val pp_get_max_indent : formatter -> unit -> int
val get_max_indent : unit -> int
type geometry = Stdlib__format.geometry = {
max_indent : int;
margin : int;
}
val check_geometry : geometry -> bool
val pp_set_geometry : formatter -> max_indent:int -> margin:int -> unit
val set_geometry : max_indent:int -> margin:int -> unit
val pp_safe_set_geometry : formatter -> max_indent:int -> margin:int -> unit
val safe_set_geometry : max_indent:int -> margin:int -> unit
val pp_update_geometry : formatter -> (geometry -> geometry) -> unit
val update_geometry : (geometry -> geometry) -> unit
val pp_get_geometry : formatter -> unit -> geometry
val get_geometry : unit -> geometry
val pp_set_max_boxes : formatter -> int -> unit
val set_max_boxes : int -> unit
val pp_get_max_boxes : formatter -> unit -> int
val get_max_boxes : unit -> int
val pp_over_max_boxes : formatter -> unit -> bool
val over_max_boxes : unit -> bool
val pp_open_tbox : formatter -> unit -> unit
val open_tbox : unit -> unit
val pp_close_tbox : formatter -> unit -> unit
val close_tbox : unit -> unit
val pp_set_tab : formatter -> unit -> unit
val set_tab : unit -> unit
val pp_print_tab : formatter -> unit -> unit
val print_tab : unit -> unit
val pp_print_tbreak : formatter -> int -> int -> unit
val print_tbreak : int -> int -> unit
val pp_set_ellipsis_text : formatter -> string -> unit
val set_ellipsis_text : string -> unit
val pp_get_ellipsis_text : formatter -> unit -> string
val get_ellipsis_text : unit -> string
type stag = Stdlib__format.stag = ..
type tag = string
type stag += String_tag of tag
val pp_open_stag : formatter -> stag -> unit
val open_stag : stag -> unit
val pp_close_stag : formatter -> unit -> unit
val close_stag : unit -> unit
val pp_set_tags : formatter -> bool -> unit
val set_tags : bool -> unit
val pp_set_print_tags : formatter -> bool -> unit
val set_print_tags : bool -> unit
val pp_set_mark_tags : formatter -> bool -> unit
val set_mark_tags : bool -> unit
val pp_get_print_tags : formatter -> unit -> bool
val get_print_tags : unit -> bool
val pp_get_mark_tags : formatter -> unit -> bool
val get_mark_tags : unit -> bool
val pp_set_formatter_out_channel : formatter -> Stdlib.out_channel -> unit
val set_formatter_out_channel : Stdlib.out_channel -> unit
val pp_set_formatter_output_functions : formatter -> (string -> int -> int -> unit) -> (unit -> unit) -> unit
val set_formatter_output_functions : (string -> int -> int -> unit) -> (unit -> unit) -> unit
val pp_get_formatter_output_functions : formatter -> unit -> (string -> int -> int -> unit) * (unit -> unit)
val get_formatter_output_functions : unit -> (string -> int -> int -> unit) * (unit -> unit)
type formatter_out_functions = Stdlib__format.formatter_out_functions = {
out_string : string -> int -> int -> unit;
out_flush : unit -> unit;
out_newline : unit -> unit;
out_spaces : int -> unit;
out_indent : int -> unit;
}
val pp_set_formatter_out_functions : formatter -> formatter_out_functions -> unit
val set_formatter_out_functions : formatter_out_functions -> unit
val pp_get_formatter_out_functions : formatter -> unit -> formatter_out_functions
val get_formatter_out_functions : unit -> formatter_out_functions
type formatter_stag_functions = Stdlib__format.formatter_stag_functions = {
mark_open_stag : stag -> string;
mark_close_stag : stag -> string;
print_open_stag : stag -> unit;
print_close_stag : stag -> unit;
}
val pp_set_formatter_stag_functions : formatter -> formatter_stag_functions -> unit
val set_formatter_stag_functions : formatter_stag_functions -> unit
val pp_get_formatter_stag_functions : formatter -> unit -> formatter_stag_functions
val get_formatter_stag_functions : unit -> formatter_stag_functions
val formatter_of_out_channel : Stdlib.out_channel -> formatter
val std_formatter : formatter
val err_formatter : formatter
val formatter_of_buffer : Stdlib.Buffer.t -> formatter
val stdbuf : Stdlib.Buffer.t
val str_formatter : formatter
val flush_str_formatter : unit -> string
val make_formatter : (string -> int -> int -> unit) -> (unit -> unit) -> formatter
val formatter_of_out_functions : formatter_out_functions -> formatter
type symbolic_output_item = Stdlib__format.symbolic_output_item =
| Output_flush
| Output_newline
| Output_string of string
| Output_spaces of int
| Output_indent of int
type symbolic_output_buffer = Stdlib__format.symbolic_output_buffer
val make_symbolic_output_buffer : unit -> symbolic_output_buffer
val clear_symbolic_output_buffer : symbolic_output_buffer -> unit
val get_symbolic_output_buffer : symbolic_output_buffer -> symbolic_output_item list
val flush_symbolic_output_buffer : symbolic_output_buffer -> symbolic_output_item list
val add_symbolic_output_item : symbolic_output_buffer -> symbolic_output_item -> unit
val formatter_of_symbolic_output_buffer : symbolic_output_buffer -> formatter
val pp_print_list : ?⁠pp_sep:(formatter -> unit -> unit) -> (formatter -> 'a -> unit) -> formatter -> 'a list -> unit
val pp_print_seq : ?⁠pp_sep:(formatter -> unit -> unit) -> (formatter -> 'a -> unit) -> formatter -> 'a Stdlib.Seq.t -> unit
val pp_print_text : formatter -> string -> unit
val pp_print_option : ?⁠none:(formatter -> unit -> unit) -> (formatter -> 'a -> unit) -> formatter -> 'a option -> unit
val pp_print_result : ok:(formatter -> 'a -> unit) -> error:(formatter -> 'e -> unit) -> formatter -> ('a'e) Stdlib.result -> unit
val fprintf : formatter -> ('aformatter, unit) Stdlib.format -> 'a
val printf : ('aformatter, unit) Stdlib.format -> 'a
val eprintf : ('aformatter, unit) Stdlib.format -> 'a
val sprintf : ('a, unit, string) Stdlib.format -> 'a
val asprintf : ('aformatter, unit, string) Stdlib.format4 -> 'a
val dprintf : ('aformatter, unit, formatter -> unit) Stdlib.format4 -> 'a
val ifprintf : formatter -> ('aformatter, unit) Stdlib.format -> 'a
val kfprintf : (formatter -> 'a) -> formatter -> ('bformatter, unit, 'a) Stdlib.format4 -> 'b
val kdprintf : ((formatter -> unit) -> 'a) -> ('bformatter, unit, 'a) Stdlib.format4 -> 'b
val ikfprintf : (formatter -> 'a) -> formatter -> ('bformatter, unit, 'a) Stdlib.format4 -> 'b
val ksprintf : (string -> 'a) -> ('b, unit, string, 'a) Stdlib.format4 -> 'b
val kasprintf : (string -> 'a) -> ('bformatter, unit, 'a) Stdlib.format4 -> 'b
val bprintf : Stdlib.Buffer.t -> ('aformatter, unit) Stdlib.format -> 'a
val kprintf : (string -> 'a) -> ('b, unit, string, 'a) Stdlib.format4 -> 'b
val set_all_formatter_output_functions : out:(string -> int -> int -> unit) -> flush:(unit -> unit) -> newline:(unit -> unit) -> spaces:(int -> unit) -> unit
val get_all_formatter_output_functions : unit -> (string -> int -> int -> unit) * (unit -> unit) * (unit -> unit) * (int -> unit)
val pp_set_all_formatter_output_functions : formatter -> out:(string -> int -> int -> unit) -> flush:(unit -> unit) -> newline:(unit -> unit) -> spaces:(int -> unit) -> unit
val pp_get_all_formatter_output_functions : formatter -> unit -> (string -> int -> int -> unit) * (unit -> unit) * (unit -> unit) * (int -> unit)
val pp_open_tag : formatter -> tag -> unit
val open_tag : tag -> unit
val pp_close_tag : formatter -> unit -> unit
val close_tag : unit -> unit
type formatter_tag_functions = Stdlib__format.formatter_tag_functions = {
mark_open_tag : tag -> string;
mark_close_tag : tag -> string;
print_open_tag : tag -> unit;
print_close_tag : tag -> unit;
}
val pp_set_formatter_tag_functions : formatter -> formatter_tag_functions -> unit
val set_formatter_tag_functions : formatter_tag_functions -> unit
val pp_get_formatter_tag_functions : formatter -> unit -> formatter_tag_functions
val get_formatter_tag_functions : unit -> formatter_tag_functions
type t = Stdlib.Format.formatter
type -'a printer = t -> 'a -> unit

Combinators

val silent : 'a printer

Prints nothing.

val unit : unit printer

Prints "()".

val int : int printer
val string : string printer
val bool : bool printer
val float3 : float printer
val float : float printer
val exn : exn printer

Printer using Printexc.to_string.

since
3.0
val space : unit printer

Alias to pp_print_space.

since
3.2
val cut : unit printer

Alias to pp_print_cut.

since
3.2
val break : (int * int) printer

Tuple-ized printer form of pp_print_break.

since
3.2
val newline : unit printer

Force newline (see Format.pp_force_newline).

since
1.2
val substring : (string * int * int) printer

substring (s,i,len) prints the substring (s,i,len), where i is the offset in s and len the number of bytes in the substring.

raises Invalid_argument

if the triple (s,i,len) does not describe a proper substring.

since
1.2
val text : string printer

Print string, but replacing spaces with breaks and newlines with newline. See pp_print_text on recent versions of OCaml.

since
1.2
val string_lines : string printer

string_lines out s prints s with all newlines ('\n') replaced by a cut, in a vertical box. It does NOT insert breakable spaces in place of spaces, unlike text. This means an already formatted string can be displayed inside another formatter without mangling the indentation.

since
3.3
val char : char printer
since
0.14
val int32 : int32 printer
since
0.14
val int64 : int64 printer
since
0.14
val nativeint : nativeint printer
since
0.14
val flush : unit printer

Alias to Format.pp_print_flush.

since
1.2
val string_quoted : string printer

Similar to CCString.print.

since
0.14
val list : ?⁠sep:unit printer -> 'a printer -> 'a list printer
val array : ?⁠sep:unit printer -> 'a printer -> 'a array printer
val arrayi : ?⁠sep:unit printer -> (int * 'a) printer -> 'a array printer
val seq : ?⁠sep:unit printer -> 'a printer -> 'a Stdlib.Seq.t printer
val iter : ?⁠sep:unit printer -> 'a printer -> 'a iter printer
val opt : 'a printer -> 'a option printer

opt pp prints options as follows:

  • Some x will become "some foo" if pp x ---> "foo".
  • None will become "none".
val pair : ?⁠sep:unit printer -> 'a printer -> 'b printer -> ('a * 'b) printer
val triple : ?⁠sep:unit printer -> 'a printer -> 'b printer -> 'c printer -> ('a * 'b * 'c) printer
val quad : ?⁠sep:unit printer -> 'a printer -> 'b printer -> 'c printer -> 'd printer -> ('a * 'b * 'c * 'd) printer
val append : unit printer -> unit printer -> unit printer

append ppa ppb first prints ppa (), then prints ppb ().

since
3.2
val append_l : unit printer list -> unit printer

append_l pps runs the printers in pps sequentially.

since
3.2
val within : string -> string -> 'a printer -> 'a printer

within a b p wraps p inside the strings a and b. Convenient, for instances, for brackets, parenthesis, quotes, etc.

since
0.17
val map : ('a -> 'b) -> 'b printer -> 'a printer
val vbox : ?⁠i:int -> 'a printer -> 'a printer

Wrap the printer in a vertical box.

parameter i

level of indentation within the box (default 0).

since
0.16
val hvbox : ?⁠i:int -> 'a printer -> 'a printer

Wrap the printer in a horizontal/vertical box.

parameter i

level of indentation within the box (default 0).

since
0.16
val hovbox : ?⁠i:int -> 'a printer -> 'a printer

Wrap the printer in a horizontal or vertical box.

parameter i

level of indentation within the box (default 0).

since
0.16
val hbox : 'a printer -> 'a printer

Wrap the printer in an horizontal box.

since
0.16
val return : ('a__'a) Stdlib.format4 -> unit printer

return "some_format_string" takes a argument-less format string and returns a printer actionable by (). Examples:

  • return ",@ "
  • return "@{<Red>and then@}@,"
  • return "@[<v>a@ b@]"
since
1.0
val of_to_string : ('a -> string) -> 'a printer

of_to_string f converts its input to a string using f, then prints the string.

since
1.0
val const : 'a printer -> 'a -> unit printer

const pp x is a unit printer that uses pp on x.

since
1.0
val some : 'a printer -> 'a option printer

some pp will print options as follows:

  • Some x is printed using pp on x
  • None is not printed at all
since
1.0
val const_string : string -> 'a printer

const_string s is a printer that ignores its input and always prints s.

since
3.5
val opaque : 'a printer

opaque is const_string "opaque". The exact string used is not stable.

since
3.5
val lazy_force : 'a printer -> 'a lazy_t printer

lazy_force pp out x forces x and prints the result with pp.

since
2.0
val lazy_or : ?⁠default:unit printer -> 'a printer -> 'a lazy_t printer

lazy_or ?default pp out x prints default if x is not evaluated yet, or uses pp otherwise.

since
2.0

ANSI codes

Use ANSI escape codes https://en.wikipedia.org/wiki/ANSI_escape_code to put some colors on the terminal.

This uses tags in format strings to specify the style. Current styles are the following:

  • "reset" resets style
  • "black"
  • "red"
  • "green"
  • "yellow"
  • "blue"
  • "magenta"
  • "cyan"
  • "white"
  • "bold" bold font
  • "Black" bold black
  • "Red" bold red
  • "Green" bold green
  • "Yellow" bold yellow
  • "Blue" bold blue
  • "Magenta" bold magenta
  • "Cyan" bold cyan
  • "White" bold white

Example:

set_color_default true;;
 
 Format.printf
   "what is your @{<White>favorite color@}? @{<blue>blue@}! No, @{<red>red@}! Ahhhhhhh@.";;

status: unstable

since
0.15
val set_color_tag_handling : t -> unit

Add functions to support color tags to the given formatter.

since
0.15
val set_color_default : bool -> unit

set_color_default b enables color handling on the standard formatters (stdout, stderr) if b = true as well as on sprintf formatters; it disables the color handling if b = false.

val with_color : string -> 'a printer -> 'a printer

with_color "Blue" pp behaves like the printer pp, but with the given style.

status: unstable

since
0.16
val with_colorf : string -> t -> ('at, unit, unit) Stdlib.format4 -> 'a

with_colorf "Blue" out "%s %d" "yolo" 42 will behave like Format.fprintf, but wrapping the content with the given style.

status: unstable

since
0.16
val with_color_sf : string -> ('at, unit, string) Stdlib.format4 -> 'a

with_color_sf "Blue" out "%s %d" "yolo" 42 will behave like sprintf, but wrapping the content with the given style.

Example:

CCFormat.with_color_sf "red" "%a" CCFormat.Dump.(list int) [1;2;3] |> print_endline;;

status: unstable

since
0.21
val with_color_ksf : f:(string -> 'b) -> string -> ('at, unit, 'b) Stdlib.format4 -> 'a

with_color_ksf "Blue" ~f "%s %d" "yolo" 42 will behave like ksprintf, but wrapping the content with the given style.

Example: the following with raise Failure with a colored message

CCFormat.with_color_ksf "red" ~f:failwith "%a" CCFormat.Dump.(list int) [1;2;3];;
since
1.2
module ANSI_codes : sig ... end

ANSI escape codes. This contains lower level functions for them.

IO

val output : t -> 'a printer -> 'a -> unit
val to_string : 'a printer -> 'a -> string
val of_chan : Stdlib.out_channel -> t

Alias to Format.formatter_of_out_channel.

since
1.2
val with_out_chan : Stdlib.out_channel -> (t -> 'a) -> 'a

with_out_chan oc f turns oc into a formatter fmt, and call f fmt. Behaves like f fmt from then on, but whether the call to f fails or returns, fmt is flushed before the call terminates.

since
1.2
val stdout : t
val stderr : t
val tee : t -> t -> t

tee a b makes a new formatter that writes in both a and b.

since
1.0
val sprintf : ('at, unit, string) Stdlib.format4 -> 'a

Print into a string any format string that would usually be compatible with fprintf. Like Format.asprintf.

val sprintf_no_color : ('at, unit, string) Stdlib.format4 -> 'a

Like sprintf but never prints colors.

since
0.16
val sprintf_dyn_color : colors:bool -> ('at, unit, string) Stdlib.format4 -> 'a

Like sprintf but enable/disable colors depending on colors.

Example:

(* with colors *)
diff --git a/dev/containers/CCHash/index.html b/dev/containers/CCHash/index.html
index d3ca2100..ce0609f4 100644
--- a/dev/containers/CCHash/index.html
+++ b/dev/containers/CCHash/index.html
@@ -1,4 +1,4 @@
 
-CCHash (containers.CCHash)

Module CCHash

Hash combinators

The API of this module is stable as per semantic versioning, like the rest of containers. However the exact implementation of hashing function can change and should not be relied on (i.e. hashing a value always returns the same integer within a run of a program, not across versions of OCaml and Containers).

Definitions

type hash = int

A hash value is a positive integer.

type 'a t = 'a -> hash

A hash function for values of type 'a.

val const : hash -> _ t

const h hashes any value into h. Use with caution!.

val const0 : _ t

Always return 0. Useful for ignoring elements. Example: Hash.(pair string const0) will map pairs ("a", 1) and ("a", 2) to the same hash, but not the same as ("b", 1).

since
1.5
val int : int t
val bool : bool t
val char : char t
val int32 : int32 t
val int64 : int64 t
val nativeint : nativeint t
val slice : string -> int -> int t

slice s i len state hashes the slice i, …, i+len-1 of s into state.

val bytes : bytes t

Hash a byte array.

since
NEXT_RELEASE
val string : string t
val list : 'a t -> 'a list t
val array : 'a t -> 'a array t
val opt : 'a t -> 'a option t
val pair : 'a t -> 'b t -> ('a * 'b) t
val triple : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t
val quad : 'a t -> 'b t -> 'c t -> 'd t -> ('a * 'b * 'c * 'd) t
val map : ('a -> 'b) -> 'b t -> 'a t

map f h is the hasher that takes x, and uses h to hash f x.

For example:

module Str_set = Set.Make(String)
+CCHash (containers.CCHash)

Module CCHash

Hash combinators

The API of this module is stable as per semantic versioning, like the rest of containers. However the exact implementation of hashing function can change and should not be relied on (i.e. hashing a value always returns the same integer within a run of a program, not across versions of OCaml and Containers).

Definitions

type hash = int

A hash value is a positive integer.

type 'a t = 'a -> hash

A hash function for values of type 'a.

val const : hash -> _ t

const h hashes any value into h. Use with caution!.

val const0 : _ t

Always return 0. Useful for ignoring elements. Example: Hash.(pair string const0) will map pairs ("a", 1) and ("a", 2) to the same hash, but not the same as ("b", 1).

since
1.5
val int : int t
val bool : bool t
val char : char t
val int32 : int32 t
val int64 : int64 t
val nativeint : nativeint t
val slice : string -> int -> int t

slice s i len state hashes the slice i, …, i+len-1 of s into state.

val bytes : bytes t

Hash a byte array.

since
3.5
val string : string t
val list : 'a t -> 'a list t
val array : 'a t -> 'a array t
val opt : 'a t -> 'a option t
val pair : 'a t -> 'b t -> ('a * 'b) t
val triple : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t
val quad : 'a t -> 'b t -> 'c t -> 'd t -> ('a * 'b * 'c * 'd) t
val map : ('a -> 'b) -> 'b t -> 'a t

map f h is the hasher that takes x, and uses h to hash f x.

For example:

module Str_set = Set.Make(String)
 
-let hash_str_set : Str_set.t CCHash.t = CCHash.(map Str_set.to_seq @@ seq string)
since
NEXT_RELEASE
val if_ : bool -> 'a t -> 'a t -> 'a t

Decide which hash function to use depending on the boolean.

val poly : 'a t

poly x is Hashtbl.hash x. The regular polymorphic hash function.

val list_comm : 'a t -> 'a list t

Commutative version of list. Lists that are equal up to permutation will have the same hash.

since
1.0
val array_comm : 'a t -> 'a array t

Commutative version of array. Arrays that are equal up to permutation will have the same hash.

since
1.0

Base hash combinators

val combine : 'a t -> hash -> 'a -> hash
val combine2 : hash -> hash -> hash
val combine3 : hash -> hash -> hash -> hash
val combine4 : hash -> hash -> hash -> hash -> hash
val combine5 : hash -> hash -> hash -> hash -> hash -> hash
since
2.1
val combine6 : hash -> hash -> hash -> hash -> hash -> hash -> hash
since
2.1

Iterators

type 'a iter = ('a -> unit) -> unit
type 'a gen = unit -> 'a option
val seq : 'a t -> 'a Stdlib.Seq.t t
val iter : 'a t -> 'a iter t
val gen : 'a t -> 'a gen t
\ No newline at end of file +let hash_str_set : Str_set.t CCHash.t = CCHash.(map Str_set.to_seq @@ seq string)
since
3.5
val if_ : bool -> 'a t -> 'a t -> 'a t

Decide which hash function to use depending on the boolean.

val poly : 'a t

poly x is Hashtbl.hash x. The regular polymorphic hash function.

val list_comm : 'a t -> 'a list t

Commutative version of list. Lists that are equal up to permutation will have the same hash.

since
1.0
val array_comm : 'a t -> 'a array t

Commutative version of array. Arrays that are equal up to permutation will have the same hash.

since
1.0

Base hash combinators

val combine : 'a t -> hash -> 'a -> hash
val combine2 : hash -> hash -> hash
val combine3 : hash -> hash -> hash -> hash
val combine4 : hash -> hash -> hash -> hash -> hash
val combine5 : hash -> hash -> hash -> hash -> hash -> hash
since
2.1
val combine6 : hash -> hash -> hash -> hash -> hash -> hash -> hash
since
2.1

Iterators

type 'a iter = ('a -> unit) -> unit
type 'a gen = unit -> 'a option
val seq : 'a t -> 'a Stdlib.Seq.t t
val iter : 'a t -> 'a iter t
val gen : 'a t -> 'a gen t
\ No newline at end of file diff --git a/dev/containers/CCIO/index.html b/dev/containers/CCIO/index.html index 53c9fb30..88445576 100644 --- a/dev/containers/CCIO/index.html +++ b/dev/containers/CCIO/index.html @@ -17,6 +17,6 @@ (fun oc -> write_gen oc chunks ) - ) ;;
since
0.6
before 0.12

was in 'containers.io', now moved into 'containers'

type 'a or_error = ('a, string) Stdlib.result
type 'a gen = unit -> 'a option

See Gen in the gen library.

Input

val with_in : ?⁠mode:int -> ?⁠flags:Stdlib.open_flag list -> string -> (Stdlib.in_channel -> 'a) -> 'a

Open an input file with the given optional flag list, calls the function on the input channel. When the function raises or returns, the channel is closed.

raises Sys_error

in case of error (same as open_in and close_in).

parameter flags

opening flags (default [Open_text]). Open_rdonly is used in any cases.

val read_chunks_gen : ?⁠size:int -> Stdlib.in_channel -> string gen

Read the channel's content into chunks of size size. NOTE the generator must be used within the lifetime of the channel, see warning at the top of the file.

val read_chunks_seq : ?⁠size:int -> Stdlib.in_channel -> string Stdlib.Seq.t

Read the channel's content into chunks of size size. NOTE the generator must be used within the lifetime of the channel, see warning at the top of the file.

since
NEXT_RELEASE
val read_line : Stdlib.in_channel -> string option

Read a line from the channel. Returns None if the input is terminated. The "\n" is removed from the line.

val read_lines_gen : Stdlib.in_channel -> string gen

Read all lines. The generator should be traversed only once. NOTE the generator must be used within the lifetime of the channel, see warning at the top of the file.

val read_lines_seq : Stdlib.in_channel -> string Stdlib.Seq.t

Read all lines. NOTE the seq must be used within the lifetime of the channel, see warning at the top of the file.

since
NEXT_RELEASE
val read_lines_l : Stdlib.in_channel -> string list

Read all lines into a list.

val read_all : ?⁠size:int -> Stdlib.in_channel -> string

Read the whole channel into a buffer, then converted into a string.

parameter size

the internal buffer size.

since
0.7
val read_all_bytes : ?⁠size:int -> Stdlib.in_channel -> Stdlib.Bytes.t

Read the whole channel into a mutable byte array.

parameter size

the internal buffer size.

since
0.12

Output

val with_out : ?⁠mode:int -> ?⁠flags:Stdlib.open_flag list -> string -> (Stdlib.out_channel -> 'a) -> 'a

Like with_in but for an output channel.

parameter flags

opening flags (default [Open_creat; Open_trunc; Open_text]).

raises Sys_error

in case of error (same as open_out and close_out). Open_wronly is used in any cases.

val with_out_a : ?⁠mode:int -> ?⁠flags:Stdlib.open_flag list -> string -> (Stdlib.out_channel -> 'a) -> 'a

Like with_out but with the [Open_append; Open_creat; Open_wronly] flags activated, to append to the file.

raises Sys_error

in case of error (same as open_out and close_out).

val write_line : Stdlib.out_channel -> string -> unit

Write the given string on the channel, followed by "\n".

val write_gen : ?⁠sep:string -> Stdlib.out_channel -> string gen -> unit

Write the given strings on the output. If provided, add sep between every two strings (but not at the end).

val write_seq : ?⁠sep:string -> Stdlib.out_channel -> string Stdlib.Seq.t -> unit

Write the given strings on the output. If provided, add sep between every two strings (but not at the end).

since
NEXT_RELEASE
val write_lines : Stdlib.out_channel -> string gen -> unit

Write every string on the output, followed by "\n".

val write_lines_seq : Stdlib.out_channel -> string Stdlib.Seq.t -> unit

Write every string on the output, followed by "\n".

since
NEXT_RELEASE
val write_lines_l : Stdlib.out_channel -> string list -> unit

Both

val with_in_out : ?⁠mode:int -> ?⁠flags:Stdlib.open_flag list -> string -> (Stdlib.in_channel -> Stdlib.out_channel -> 'a) -> 'a

Combines with_in and with_out.

parameter flags

opening flags (default [Open_creat]).

raises Sys_error

in case of error.

since
0.12
val copy_into : ?⁠bufsize:int -> Stdlib.in_channel -> Stdlib.out_channel -> unit

copy_into ic oc writes the content of ic into oc. It is a blocking call.

since
3.0

Misc for Generators

val tee : ('a -> unit) list -> 'a gen -> 'a gen

tee funs gen behaves like gen, but each element is given to every function f in funs at the time the element is produced. The returned generator will raise any exception that f raises

File and file names

How to list recursively files in a directory:

# let files = CCIO.File.read_dir ~recurse:true (CCIO.File.make "/tmp");;
+  ) ;;
since
0.6
before 0.12

was in 'containers.io', now moved into 'containers'

type 'a or_error = ('a, string) Stdlib.result
type 'a gen = unit -> 'a option

See Gen in the gen library.

Input

val with_in : ?⁠mode:int -> ?⁠flags:Stdlib.open_flag list -> string -> (Stdlib.in_channel -> 'a) -> 'a

Open an input file with the given optional flag list, calls the function on the input channel. When the function raises or returns, the channel is closed.

raises Sys_error

in case of error (same as open_in and close_in).

parameter flags

opening flags (default [Open_text]). Open_rdonly is used in any cases.

val read_chunks_gen : ?⁠size:int -> Stdlib.in_channel -> string gen

Read the channel's content into chunks of size size. NOTE the generator must be used within the lifetime of the channel, see warning at the top of the file.

val read_chunks_seq : ?⁠size:int -> Stdlib.in_channel -> string Stdlib.Seq.t

Read the channel's content into chunks of size size. NOTE the generator must be used within the lifetime of the channel, see warning at the top of the file.

since
3.5
val read_line : Stdlib.in_channel -> string option

Read a line from the channel. Returns None if the input is terminated. The "\n" is removed from the line.

val read_lines_gen : Stdlib.in_channel -> string gen

Read all lines. The generator should be traversed only once. NOTE the generator must be used within the lifetime of the channel, see warning at the top of the file.

val read_lines_seq : Stdlib.in_channel -> string Stdlib.Seq.t

Read all lines. NOTE the seq must be used within the lifetime of the channel, see warning at the top of the file.

since
3.5
val read_lines_l : Stdlib.in_channel -> string list

Read all lines into a list.

val read_all : ?⁠size:int -> Stdlib.in_channel -> string

Read the whole channel into a buffer, then converted into a string.

parameter size

the internal buffer size.

since
0.7
val read_all_bytes : ?⁠size:int -> Stdlib.in_channel -> Stdlib.Bytes.t

Read the whole channel into a mutable byte array.

parameter size

the internal buffer size.

since
0.12

Output

val with_out : ?⁠mode:int -> ?⁠flags:Stdlib.open_flag list -> string -> (Stdlib.out_channel -> 'a) -> 'a

Like with_in but for an output channel.

parameter flags

opening flags (default [Open_creat; Open_trunc; Open_text]).

raises Sys_error

in case of error (same as open_out and close_out). Open_wronly is used in any cases.

val with_out_a : ?⁠mode:int -> ?⁠flags:Stdlib.open_flag list -> string -> (Stdlib.out_channel -> 'a) -> 'a

Like with_out but with the [Open_append; Open_creat; Open_wronly] flags activated, to append to the file.

raises Sys_error

in case of error (same as open_out and close_out).

val write_line : Stdlib.out_channel -> string -> unit

Write the given string on the channel, followed by "\n".

val write_gen : ?⁠sep:string -> Stdlib.out_channel -> string gen -> unit

Write the given strings on the output. If provided, add sep between every two strings (but not at the end).

val write_seq : ?⁠sep:string -> Stdlib.out_channel -> string Stdlib.Seq.t -> unit

Write the given strings on the output. If provided, add sep between every two strings (but not at the end).

since
3.5
val write_lines : Stdlib.out_channel -> string gen -> unit

Write every string on the output, followed by "\n".

val write_lines_seq : Stdlib.out_channel -> string Stdlib.Seq.t -> unit

Write every string on the output, followed by "\n".

since
3.5
val write_lines_l : Stdlib.out_channel -> string list -> unit

Both

val with_in_out : ?⁠mode:int -> ?⁠flags:Stdlib.open_flag list -> string -> (Stdlib.in_channel -> Stdlib.out_channel -> 'a) -> 'a

Combines with_in and with_out.

parameter flags

opening flags (default [Open_creat]).

raises Sys_error

in case of error.

since
0.12
val copy_into : ?⁠bufsize:int -> Stdlib.in_channel -> Stdlib.out_channel -> unit

copy_into ic oc writes the content of ic into oc. It is a blocking call.

since
3.0

Misc for Generators

val tee : ('a -> unit) list -> 'a gen -> 'a gen

tee funs gen behaves like gen, but each element is given to every function f in funs at the time the element is produced. The returned generator will raise any exception that f raises

File and file names

How to list recursively files in a directory:

# let files = CCIO.File.read_dir ~recurse:true (CCIO.File.make "/tmp");;
 # CCIO.write_lines stdout files;;

See File.walk if you also need to list directories:

# let content = CCIO.File.walk (CCIO.File.make "/tmp");;
 # Gen.map CCIO.File.show_walk_item content |> CCIO.write_lines stdout;;
module File : sig ... end
\ No newline at end of file diff --git a/dev/containers/CCList/index.html b/dev/containers/CCList/index.html index 7f27434d..f3f6f1a0 100644 --- a/dev/containers/CCList/index.html +++ b/dev/containers/CCList/index.html @@ -9,4 +9,4 @@ return @@ x * x;; val square_even : int list -> int list = <fun> # square_even [1;2;4;3;5;2];; -- : int list = [4; 16; 4]
since
3.1
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t

funs <*> l is product (fun f x -> f x) funs l.

val (<$>) : ('a -> 'b) -> 'a t -> 'b t

(<$>) is map.

val return : 'a -> 'a t

return x is x.

val (>>=) : 'a t -> ('a -> 'b t) -> 'b t

l >>= f is flat_map f l.

val take : int -> 'a t -> 'a t

take n l takes the n first elements of the list l, drop the rest.

val drop : int -> 'a t -> 'a t

drop n l drops the n first elements of the list l, keep the rest.

val hd_tl : 'a t -> 'a * 'a t

hd_tl (x :: l) returns hd, l.

raises Failure

if the list is empty.

since
0.16
val take_drop : int -> 'a t -> 'a t * 'a t

take_drop n l returns l1, l2 such that l1 @ l2 = l and length l1 = min (length l) n.

val take_while : ('a -> bool) -> 'a t -> 'a t

take_while f l returns the longest prefix of l for which f is true.

since
0.13
val drop_while : ('a -> bool) -> 'a t -> 'a t

drop_while f l drops the longest prefix of l for which f is true.

since
0.13
val take_drop_while : ('a -> bool) -> 'a t -> 'a t * 'a t

take_drop_while p l = take_while p l, drop_while p l.

since
1.2, but only
since
2.2 with labels
val last : int -> 'a t -> 'a t

last n l takes the last n elements of l (or less if l doesn't have that many elements).

val head_opt : 'a t -> 'a option

head_opt l returns Some x (the first element of the list l) or None if the list l is empty.

since
0.20
val tail_opt : 'a t -> 'a t option

tail_opt l returns Some l' (the given list l without its first element) or None if the list l is empty.

since
2.0
val last_opt : 'a t -> 'a option

last_opt l returns Some x (the last element of l) or None if the list l is empty.

since
0.20
val find_pred : ('a -> bool) -> 'a t -> 'a option

find_pred p l finds the first element of l that satisfies p, or returns None if no element satisfies p.

since
0.11
val find_opt : ('a -> bool) -> 'a t -> 'a option

find_opt p l is the safe version of find.

since
1.5, but only
since
2.2 with labels
val find_pred_exn : ('a -> bool) -> 'a t -> 'a

find_pred_exn p l is the unsafe version of find_pred.

raises Not_found

if no such element is found.

since
0.11
val find_map : ('a -> 'b option) -> 'a t -> 'b option

find_map f l traverses l, applying f to each element. If for some element x, f x = Some y, then Some y is returned. Otherwise the call returns None.

since
0.11
val find_mapi : (int -> 'a -> 'b option) -> 'a t -> 'b option

find_mapi f l is like find_map, but also pass the index to the predicate function.

since
0.11
val find_idx : ('a -> bool) -> 'a t -> (int * 'a) option

find_idx p x returns Some (i,x) where x is the i-th element of l, and p x holds. Otherwise returns None.

val remove : eq:('a -> 'a -> bool) -> key:'a -> 'a t -> 'a t

remove ~eq ~key l removes every instance of key from l. Tail-recursive.

parameter eq

equality function.

since
0.11
val filter_map : ('a -> 'b option) -> 'a t -> 'b t

filter_map f l is the sublist of l containing only elements for which f returns Some e. Map and remove elements at the same time.

val keep_some : 'a option t -> 'a t

keep_some l retains only elements of the form Some x. Like filter_map CCFun.id.

since
1.3, but only
since
2.2 with labels
val keep_ok : ('a_) Stdlib.result t -> 'a t

keep_ok l retains only elements of the form Ok x.

since
1.3, but only
since
2.2 with labels
val all_some : 'a option t -> 'a t option

all_some l returns Some l' if all elements of l are of the form Some x, or None otherwise.

since
1.3, but only
since
2.2 with labels
val all_ok : ('a'err) Stdlib.result t -> ('a t'err) Stdlib.result

all_ok l returns Ok l' if all elements of l are of the form Ok x, or Error e otherwise (with the first error met).

since
1.3, but only
since
2.2 with labels
val sorted_mem : cmp:('a -> 'a -> int) -> 'a -> 'a list -> bool

sorted_mem ~cmp x l and mem x l give the same result for any sorted list l, but potentially more efficiently.

since
NEXT_RELEASE
val sorted_merge : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list

sorted_merge ~cmp l1 l2 merges elements from both sorted list using the given comparison function cmp.

val sorted_diff : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list

sorted_diff ~cmp l1 l2 returns the elements in l1 that are not in l2. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff ~cmp [1;1;1;2;2;3] [1;2;2] would be [1;1;3]. It is the left inverse of sorted_merge; that is, sorted_diff ~cmp (sorted_merge ~cmp l1 l2) l2 is always equal to l1 for sorted lists l1 and l2.

since
NEXT_RELEASE
val sort_uniq : cmp:('a -> 'a -> int) -> 'a list -> 'a list

sort_uniq ~cmp l sorts the list l using the given comparison function cmp and remove duplicate elements.

val sorted_merge_uniq : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list

sorted_merge_uniq ~cmp l1 l2 merges the sorted lists l1 and l2 and removes duplicates.

since
0.10
val sorted_diff_uniq : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list

sorted_diff_uniq ~cmp l1 l2 collects the elements in l1 that are not in l2 and then remove duplicates. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff_uniq ~cmp [1;1;1;2;2] [1;2;2;2] would be [1]. sorted_diff_uniq ~cmp l1 l2 and uniq_succ ~eq (sorted_diff ~cmp l1 l2) always give the same result for sorted l1 and l2 and compatible cmp and eq.

since
NEXT_RELEASE
val is_sorted : cmp:('a -> 'a -> int) -> 'a list -> bool

is_sorted ~cmp l returns true iff l is sorted (according to given order).

parameter cmp

the comparison function.

since
0.17
val sorted_insert : cmp:('a -> 'a -> int) -> ?⁠uniq:bool -> 'a -> 'a list -> 'a list

sorted_insert ~cmp ?uniq x l inserts x into l such that, if l was sorted, then sorted_insert x l is sorted too.

parameter uniq

if true and x is already in sorted position in l, then x is not duplicated. Default false (x will be inserted in any case).

since
0.17
val sorted_remove : cmp:('a -> 'a -> int) -> ?⁠all:bool -> 'a -> 'a list -> 'a list

sorted_remove ~cmp x l removes x from a sorted list l such that the return value is sorted too. By default, it is the left inverse of sorted_insert; that is, sorted_remove ~cmp x (sorted_insert ~cmp x l) is equal to l for any sorted list l.

parameter all

if true then all occurrences of x will be removed. Otherwise, only the first x will be removed (if any). Default false (only the first will be removed).

since
NEXT_RELEASE
val uniq_succ : eq:('a -> 'a -> bool) -> 'a list -> 'a list

uniq_succ ~eq l removes duplicate elements that occur one next to the other. Examples: uniq_succ ~eq:(=) [1;2;1] = [1;2;1]. uniq_succ ~eq:(=) [1;1;2] = [1;2].

since
0.10
val group_succ : eq:('a -> 'a -> bool) -> 'a list -> 'a list list

group_succ ~eq l groups together consecutive elements that are equal according to eq.

since
0.11

Indices

val mapi : (int -> 'a -> 'b) -> 'a t -> 'b t

mapi f l is like map, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.

val iteri : (int -> 'a -> unit) -> 'a t -> unit

iteri f l is like iter, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.

val iteri2 : (int -> 'a -> 'b -> unit) -> 'a t -> 'b t -> unit

iteri2 f l1 l2 applies f to the two lists l1 and l2 simultaneously. The integer passed to f indicates the index of element.

raises Invalid_argument

when lists do not have the same length.

since
2.0, but only
since
2.2 with labels
val foldi : ('b -> int -> 'a -> 'b) -> 'b -> 'a t -> 'b

foldi f init l is like fold but it also passes in the index of each element, from 0 to length l - 1 as additional argument to the folded function f. Tail-recursive.

val foldi2 : ('c -> int -> 'a -> 'b -> 'c) -> 'c -> 'a t -> 'b t -> 'c

foldi2 f init l1 l2 folds on the two lists l1 and l2, with index of each element passed to the function f. Computes f(… (f init i_0 l1_0 l2_0) …) i_n l1_n l2_n .

raises Invalid_argument

when lists do not have the same length.

since
2.0, but only
since
2.2 with labels
val get_at_idx : int -> 'a t -> 'a option

get_at_idx i l returns Some i-th element of the given list l or None if the list l is too short. If the index is negative, it will get element starting from the end of the list l.

val nth_opt : 'a t -> int -> 'a option

nth_opt l n returns Some n-th element of l. Safe version of nth.

raises Invalid_argument

if the int is negative.

since
1.5, but only
since
2.2 with labels
val get_at_idx_exn : int -> 'a t -> 'a

get_at_idx_exn i l gets the i-th element of l, or

raises Not_found

if the index is invalid. The first element has index 0. If the index is negative, it will get element starting from the end of the list.

val set_at_idx : int -> 'a -> 'a t -> 'a t

set_at_idx i x l replaces the i-th element with x (removes the old one), or does nothing if index is too high. If the index is negative, it will set element starting from the end of the list.

val insert_at_idx : int -> 'a -> 'a t -> 'a t

insert_at_idx i x l inserts x at i-th position, between the two existing elements. If the index is too high, append at the end of the list. If the index is negative, it will insert element starting from the end of the list.

val remove_at_idx : int -> 'a t -> 'a t

remove_at_idx i l removes element at given index i. Does nothing if the index is too high. If the index is negative, it will remove element starting from the end of the list.

Set Operators

Those operations maintain the invariant that the list does not contain duplicates (if it already satisfies it).

val add_nodup : eq:('a -> 'a -> bool) -> 'a -> 'a t -> 'a t

add_nodup ~eq x set adds x to set if it was not already present. Linear time.

since
0.11
val remove_one : eq:('a -> 'a -> bool) -> 'a -> 'a t -> 'a t

remove_one ~eq x set removes one occurrence of x from set. Linear time.

since
0.11
val mem : ?⁠eq:('a -> 'a -> bool) -> 'a -> 'a t -> bool

mem ?eq x l is true iff x is equal to an element of l. A comparator function eq can be provided. Linear time.

val subset : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> bool

subset ~eq l1 l2 tests if all elements of the list l1 are contained in the list l2 by applying eq.

val uniq : eq:('a -> 'a -> bool) -> 'a t -> 'a t

uniq ~eq l removes duplicates in l w.r.t the equality predicate eq. Complexity is quadratic in the length of the list, but the order of elements is preserved. If you wish for a faster de-duplication but do not care about the order, use sort_uniq.

val union : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> 'a t

union ~eq l1 l2 is the union of the lists l1 and l2 w.r.t. the equality predicate eq. Complexity is product of length of inputs.

val inter : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> 'a t

inter ~eq l1 l2 is the intersection of the lists l1 and l2 w.r.t. the equality predicate eq. Complexity is product of length of inputs.

Other Constructors

val range_by : step:int -> int -> int -> int t

range_by ~step i j iterates on integers from i to j included, where the difference between successive elements is step. Use a negative step for a decreasing list.

raises Invalid_argument

if step=0.

since
0.18
val range : int -> int -> int t

range i j iterates on integers from i to j included. It works both for decreasing and increasing ranges.

val range' : int -> int -> int t

range' i j is like range but the second bound j is excluded. For instance range' 0 5 = [0;1;2;3;4].

val (--) : int -> int -> int t

i -- j is the list of integers from i to j included. Infix alias for range.

val (--^) : int -> int -> int t

i --^ j is the list of integers from i to j excluded. Infix alias for range'.

since
0.17
val replicate : int -> 'a -> 'a t

replicate n x replicates the given element x n times.

val repeat : int -> 'a t -> 'a t

repeat n l concatenates the list l with itself n times.

Association Lists

module Assoc : sig ... end
val assoc : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'b

assoc ~eq k alist returns the value v associated with key k in alist. Like Assoc.get_exn.

since
2.0
val assoc_opt : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'b option

assoc_opt ~eq k alist returns Some v if the given key k is present into alist, or None if not present. Like Assoc.get.

since
1.5, but only
since
2.0 with labels
val assq_opt : 'a -> ('a * 'b) t -> 'b option

assq_opt k alist returns Some v if the given key k is present into alist. Like Assoc.assoc_opt but use physical equality instead of structural equality to compare keys. Safe version of assq.

since
1.5, but only
since
2.0 with labels
val mem_assoc : ?⁠eq:('a -> 'a -> bool) -> 'a -> ('a * _) t -> bool

mem_assoc ?eq k alist returns true iff k is a key in alist. Like Assoc.mem.

since
2.0
val remove_assoc : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> ('a * 'b) t

remove_assoc ~eq k alist returns the alist without the first pair with key k, if any. Like Assoc.remove.

since
2.0

References on Lists

since
0.3.3
module Ref : sig ... end
module type MONAD = sig ... end
module Traverse : functor (M : MONAD) -> sig ... end

Conversions

val random : 'a random_gen -> 'a t random_gen
val random_non_empty : 'a random_gen -> 'a t random_gen
val random_len : int -> 'a random_gen -> 'a t random_gen
val random_choose : 'a t -> 'a random_gen

random_choose l randomly chooses an element in the list l.

raises Not_found

if the list is empty.

val random_sequence : 'a random_gen t -> 'a t random_gen
val to_string : ?⁠start:string -> ?⁠stop:string -> ?⁠sep:string -> ('a -> string) -> 'a t -> string

to_string ?start ?stop ?sep item_to_string l prints l to a string using sep as a separator between elements of l.

since
2.7
val to_iter : 'a t -> 'a iter

to_iter l returns a iter of the elements of the list l.

since
2.8
val to_seq : 'a t -> 'a Stdlib.Seq.t

to_seq l returns a Seq.t of the elements of the list l. Renamed from to_std_seq since 3.0.

since
3.0
val of_iter : 'a iter -> 'a t

of_iter iter builds a list from a given iter. In the result, elements appear in the same order as they did in the source iter.

since
2.8
val of_seq_rev : 'a Stdlib.Seq.t -> 'a t

of_seq_rev seq builds a list from a given Seq.t, in reverse order. Renamed from to_std_seq_rev since 3.0.

since
3.0
val of_seq : 'a Stdlib.Seq.t -> 'a t

of_seq seq builds a list from a given Seq.t. In the result, elements appear in the same order as they did in the source Seq.t. Renamed from of_std_seq since 3.0.

since
3.0
val to_gen : 'a t -> 'a gen

to_gen l returns a gen of the elements of the list l.

val of_gen : 'a gen -> 'a t

of_gen gen builds a list from a given gen. In the result, elements appear in the same order as they did in the source gen.

Infix Operators

It is convenient to open CCList.Infix to access the infix operators without cluttering the scope too much.

since
0.16
module Infix : sig ... end

Let operators on OCaml >= 4.08.0, nothing otherwise

since
2.8
include CCShimsMkLet_.S with type 'a t_let := 'a list
type 'a t_let
val let+ : 'a t_let -> ('a -> 'b) -> 'b t_let
val and+ : 'a t_let -> 'b t_let -> ('a * 'b) t_let
val let* : 'a t_let -> ('a -> 'b t_let) -> 'b t_let
val and* : 'a t_let -> 'b t_let -> ('a * 'b) t_let

IO

val pp : ?⁠pp_start:unit printer -> ?⁠pp_stop:unit printer -> ?⁠pp_sep:unit printer -> 'a printer -> 'a t printer

pp ?pp_start ?pp_stop ?pp_sep ppf l prints the contents of a list.

\ No newline at end of file +- : int list = [4; 16; 4]
since
3.1
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t

funs <*> l is product (fun f x -> f x) funs l.

val (<$>) : ('a -> 'b) -> 'a t -> 'b t

(<$>) is map.

val return : 'a -> 'a t

return x is x.

val (>>=) : 'a t -> ('a -> 'b t) -> 'b t

l >>= f is flat_map f l.

val take : int -> 'a t -> 'a t

take n l takes the n first elements of the list l, drop the rest.

val drop : int -> 'a t -> 'a t

drop n l drops the n first elements of the list l, keep the rest.

val hd_tl : 'a t -> 'a * 'a t

hd_tl (x :: l) returns hd, l.

raises Failure

if the list is empty.

since
0.16
val take_drop : int -> 'a t -> 'a t * 'a t

take_drop n l returns l1, l2 such that l1 @ l2 = l and length l1 = min (length l) n.

val take_while : ('a -> bool) -> 'a t -> 'a t

take_while f l returns the longest prefix of l for which f is true.

since
0.13
val drop_while : ('a -> bool) -> 'a t -> 'a t

drop_while f l drops the longest prefix of l for which f is true.

since
0.13
val take_drop_while : ('a -> bool) -> 'a t -> 'a t * 'a t

take_drop_while p l = take_while p l, drop_while p l.

since
1.2, but only
since
2.2 with labels
val last : int -> 'a t -> 'a t

last n l takes the last n elements of l (or less if l doesn't have that many elements).

val head_opt : 'a t -> 'a option

head_opt l returns Some x (the first element of the list l) or None if the list l is empty.

since
0.20
val tail_opt : 'a t -> 'a t option

tail_opt l returns Some l' (the given list l without its first element) or None if the list l is empty.

since
2.0
val last_opt : 'a t -> 'a option

last_opt l returns Some x (the last element of l) or None if the list l is empty.

since
0.20
val find_pred : ('a -> bool) -> 'a t -> 'a option

find_pred p l finds the first element of l that satisfies p, or returns None if no element satisfies p.

since
0.11
val find_opt : ('a -> bool) -> 'a t -> 'a option

find_opt p l is the safe version of find.

since
1.5, but only
since
2.2 with labels
val find_pred_exn : ('a -> bool) -> 'a t -> 'a

find_pred_exn p l is the unsafe version of find_pred.

raises Not_found

if no such element is found.

since
0.11
val find_map : ('a -> 'b option) -> 'a t -> 'b option

find_map f l traverses l, applying f to each element. If for some element x, f x = Some y, then Some y is returned. Otherwise the call returns None.

since
0.11
val find_mapi : (int -> 'a -> 'b option) -> 'a t -> 'b option

find_mapi f l is like find_map, but also pass the index to the predicate function.

since
0.11
val find_idx : ('a -> bool) -> 'a t -> (int * 'a) option

find_idx p x returns Some (i,x) where x is the i-th element of l, and p x holds. Otherwise returns None.

val remove : eq:('a -> 'a -> bool) -> key:'a -> 'a t -> 'a t

remove ~eq ~key l removes every instance of key from l. Tail-recursive.

parameter eq

equality function.

since
0.11
val filter_map : ('a -> 'b option) -> 'a t -> 'b t

filter_map f l is the sublist of l containing only elements for which f returns Some e. Map and remove elements at the same time.

val keep_some : 'a option t -> 'a t

keep_some l retains only elements of the form Some x. Like filter_map CCFun.id.

since
1.3, but only
since
2.2 with labels
val keep_ok : ('a_) Stdlib.result t -> 'a t

keep_ok l retains only elements of the form Ok x.

since
1.3, but only
since
2.2 with labels
val all_some : 'a option t -> 'a t option

all_some l returns Some l' if all elements of l are of the form Some x, or None otherwise.

since
1.3, but only
since
2.2 with labels
val all_ok : ('a'err) Stdlib.result t -> ('a t'err) Stdlib.result

all_ok l returns Ok l' if all elements of l are of the form Ok x, or Error e otherwise (with the first error met).

since
1.3, but only
since
2.2 with labels
val sorted_mem : cmp:('a -> 'a -> int) -> 'a -> 'a list -> bool

sorted_mem ~cmp x l and mem x l give the same result for any sorted list l, but potentially more efficiently.

since
3.5
val sorted_merge : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list

sorted_merge ~cmp l1 l2 merges elements from both sorted list using the given comparison function cmp.

val sorted_diff : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list

sorted_diff ~cmp l1 l2 returns the elements in l1 that are not in l2. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff ~cmp [1;1;1;2;2;3] [1;2;2] would be [1;1;3]. It is the left inverse of sorted_merge; that is, sorted_diff ~cmp (sorted_merge ~cmp l1 l2) l2 is always equal to l1 for sorted lists l1 and l2.

since
3.5
val sort_uniq : cmp:('a -> 'a -> int) -> 'a list -> 'a list

sort_uniq ~cmp l sorts the list l using the given comparison function cmp and remove duplicate elements.

val sorted_merge_uniq : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list

sorted_merge_uniq ~cmp l1 l2 merges the sorted lists l1 and l2 and removes duplicates.

since
0.10
val sorted_diff_uniq : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list

sorted_diff_uniq ~cmp l1 l2 collects the elements in l1 that are not in l2 and then remove duplicates. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff_uniq ~cmp [1;1;1;2;2] [1;2;2;2] would be [1]. sorted_diff_uniq ~cmp l1 l2 and uniq_succ ~eq (sorted_diff ~cmp l1 l2) always give the same result for sorted l1 and l2 and compatible cmp and eq.

since
3.5
val is_sorted : cmp:('a -> 'a -> int) -> 'a list -> bool

is_sorted ~cmp l returns true iff l is sorted (according to given order).

parameter cmp

the comparison function.

since
0.17
val sorted_insert : cmp:('a -> 'a -> int) -> ?⁠uniq:bool -> 'a -> 'a list -> 'a list

sorted_insert ~cmp ?uniq x l inserts x into l such that, if l was sorted, then sorted_insert x l is sorted too.

parameter uniq

if true and x is already in sorted position in l, then x is not duplicated. Default false (x will be inserted in any case).

since
0.17
val sorted_remove : cmp:('a -> 'a -> int) -> ?⁠all:bool -> 'a -> 'a list -> 'a list

sorted_remove ~cmp x l removes x from a sorted list l such that the return value is sorted too. By default, it is the left inverse of sorted_insert; that is, sorted_remove ~cmp x (sorted_insert ~cmp x l) is equal to l for any sorted list l.

parameter all

if true then all occurrences of x will be removed. Otherwise, only the first x will be removed (if any). Default false (only the first will be removed).

since
3.5
val uniq_succ : eq:('a -> 'a -> bool) -> 'a list -> 'a list

uniq_succ ~eq l removes duplicate elements that occur one next to the other. Examples: uniq_succ ~eq:(=) [1;2;1] = [1;2;1]. uniq_succ ~eq:(=) [1;1;2] = [1;2].

since
0.10
val group_succ : eq:('a -> 'a -> bool) -> 'a list -> 'a list list

group_succ ~eq l groups together consecutive elements that are equal according to eq.

since
0.11

Indices

val mapi : (int -> 'a -> 'b) -> 'a t -> 'b t

mapi f l is like map, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.

val iteri : (int -> 'a -> unit) -> 'a t -> unit

iteri f l is like iter, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.

val iteri2 : (int -> 'a -> 'b -> unit) -> 'a t -> 'b t -> unit

iteri2 f l1 l2 applies f to the two lists l1 and l2 simultaneously. The integer passed to f indicates the index of element.

raises Invalid_argument

when lists do not have the same length.

since
2.0, but only
since
2.2 with labels
val foldi : ('b -> int -> 'a -> 'b) -> 'b -> 'a t -> 'b

foldi f init l is like fold but it also passes in the index of each element, from 0 to length l - 1 as additional argument to the folded function f. Tail-recursive.

val foldi2 : ('c -> int -> 'a -> 'b -> 'c) -> 'c -> 'a t -> 'b t -> 'c

foldi2 f init l1 l2 folds on the two lists l1 and l2, with index of each element passed to the function f. Computes f(… (f init i_0 l1_0 l2_0) …) i_n l1_n l2_n .

raises Invalid_argument

when lists do not have the same length.

since
2.0, but only
since
2.2 with labels
val get_at_idx : int -> 'a t -> 'a option

get_at_idx i l returns Some i-th element of the given list l or None if the list l is too short. If the index is negative, it will get element starting from the end of the list l.

val nth_opt : 'a t -> int -> 'a option

nth_opt l n returns Some n-th element of l. Safe version of nth.

raises Invalid_argument

if the int is negative.

since
1.5, but only
since
2.2 with labels
val get_at_idx_exn : int -> 'a t -> 'a

get_at_idx_exn i l gets the i-th element of l, or

raises Not_found

if the index is invalid. The first element has index 0. If the index is negative, it will get element starting from the end of the list.

val set_at_idx : int -> 'a -> 'a t -> 'a t

set_at_idx i x l replaces the i-th element with x (removes the old one), or does nothing if index is too high. If the index is negative, it will set element starting from the end of the list.

val insert_at_idx : int -> 'a -> 'a t -> 'a t

insert_at_idx i x l inserts x at i-th position, between the two existing elements. If the index is too high, append at the end of the list. If the index is negative, it will insert element starting from the end of the list.

val remove_at_idx : int -> 'a t -> 'a t

remove_at_idx i l removes element at given index i. Does nothing if the index is too high. If the index is negative, it will remove element starting from the end of the list.

Set Operators

Those operations maintain the invariant that the list does not contain duplicates (if it already satisfies it).

val add_nodup : eq:('a -> 'a -> bool) -> 'a -> 'a t -> 'a t

add_nodup ~eq x set adds x to set if it was not already present. Linear time.

since
0.11
val remove_one : eq:('a -> 'a -> bool) -> 'a -> 'a t -> 'a t

remove_one ~eq x set removes one occurrence of x from set. Linear time.

since
0.11
val mem : ?⁠eq:('a -> 'a -> bool) -> 'a -> 'a t -> bool

mem ?eq x l is true iff x is equal to an element of l. A comparator function eq can be provided. Linear time.

val subset : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> bool

subset ~eq l1 l2 tests if all elements of the list l1 are contained in the list l2 by applying eq.

val uniq : eq:('a -> 'a -> bool) -> 'a t -> 'a t

uniq ~eq l removes duplicates in l w.r.t the equality predicate eq. Complexity is quadratic in the length of the list, but the order of elements is preserved. If you wish for a faster de-duplication but do not care about the order, use sort_uniq.

val union : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> 'a t

union ~eq l1 l2 is the union of the lists l1 and l2 w.r.t. the equality predicate eq. Complexity is product of length of inputs.

val inter : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> 'a t

inter ~eq l1 l2 is the intersection of the lists l1 and l2 w.r.t. the equality predicate eq. Complexity is product of length of inputs.

Other Constructors

val range_by : step:int -> int -> int -> int t

range_by ~step i j iterates on integers from i to j included, where the difference between successive elements is step. Use a negative step for a decreasing list.

raises Invalid_argument

if step=0.

since
0.18
val range : int -> int -> int t

range i j iterates on integers from i to j included. It works both for decreasing and increasing ranges.

val range' : int -> int -> int t

range' i j is like range but the second bound j is excluded. For instance range' 0 5 = [0;1;2;3;4].

val (--) : int -> int -> int t

i -- j is the list of integers from i to j included. Infix alias for range.

val (--^) : int -> int -> int t

i --^ j is the list of integers from i to j excluded. Infix alias for range'.

since
0.17
val replicate : int -> 'a -> 'a t

replicate n x replicates the given element x n times.

val repeat : int -> 'a t -> 'a t

repeat n l concatenates the list l with itself n times.

Association Lists

module Assoc : sig ... end
val assoc : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'b

assoc ~eq k alist returns the value v associated with key k in alist. Like Assoc.get_exn.

since
2.0
val assoc_opt : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'b option

assoc_opt ~eq k alist returns Some v if the given key k is present into alist, or None if not present. Like Assoc.get.

since
1.5, but only
since
2.0 with labels
val assq_opt : 'a -> ('a * 'b) t -> 'b option

assq_opt k alist returns Some v if the given key k is present into alist. Like Assoc.assoc_opt but use physical equality instead of structural equality to compare keys. Safe version of assq.

since
1.5, but only
since
2.0 with labels
val mem_assoc : ?⁠eq:('a -> 'a -> bool) -> 'a -> ('a * _) t -> bool

mem_assoc ?eq k alist returns true iff k is a key in alist. Like Assoc.mem.

since
2.0
val remove_assoc : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> ('a * 'b) t

remove_assoc ~eq k alist returns the alist without the first pair with key k, if any. Like Assoc.remove.

since
2.0

References on Lists

since
0.3.3
module Ref : sig ... end
module type MONAD = sig ... end
module Traverse : functor (M : MONAD) -> sig ... end

Conversions

val random : 'a random_gen -> 'a t random_gen
val random_non_empty : 'a random_gen -> 'a t random_gen
val random_len : int -> 'a random_gen -> 'a t random_gen
val random_choose : 'a t -> 'a random_gen

random_choose l randomly chooses an element in the list l.

raises Not_found

if the list is empty.

val random_sequence : 'a random_gen t -> 'a t random_gen
val to_string : ?⁠start:string -> ?⁠stop:string -> ?⁠sep:string -> ('a -> string) -> 'a t -> string

to_string ?start ?stop ?sep item_to_string l prints l to a string using sep as a separator between elements of l.

since
2.7
val to_iter : 'a t -> 'a iter

to_iter l returns a iter of the elements of the list l.

since
2.8
val to_seq : 'a t -> 'a Stdlib.Seq.t

to_seq l returns a Seq.t of the elements of the list l. Renamed from to_std_seq since 3.0.

since
3.0
val of_iter : 'a iter -> 'a t

of_iter iter builds a list from a given iter. In the result, elements appear in the same order as they did in the source iter.

since
2.8
val of_seq_rev : 'a Stdlib.Seq.t -> 'a t

of_seq_rev seq builds a list from a given Seq.t, in reverse order. Renamed from to_std_seq_rev since 3.0.

since
3.0
val of_seq : 'a Stdlib.Seq.t -> 'a t

of_seq seq builds a list from a given Seq.t. In the result, elements appear in the same order as they did in the source Seq.t. Renamed from of_std_seq since 3.0.

since
3.0
val to_gen : 'a t -> 'a gen

to_gen l returns a gen of the elements of the list l.

val of_gen : 'a gen -> 'a t

of_gen gen builds a list from a given gen. In the result, elements appear in the same order as they did in the source gen.

Infix Operators

It is convenient to open CCList.Infix to access the infix operators without cluttering the scope too much.

since
0.16
module Infix : sig ... end

Let operators on OCaml >= 4.08.0, nothing otherwise

since
2.8
include CCShimsMkLet_.S with type 'a t_let := 'a list
type 'a t_let
val let+ : 'a t_let -> ('a -> 'b) -> 'b t_let
val and+ : 'a t_let -> 'b t_let -> ('a * 'b) t_let
val let* : 'a t_let -> ('a -> 'b t_let) -> 'b t_let
val and* : 'a t_let -> 'b t_let -> ('a * 'b) t_let

IO

val pp : ?⁠pp_start:unit printer -> ?⁠pp_stop:unit printer -> ?⁠pp_sep:unit printer -> 'a printer -> 'a t printer

pp ?pp_start ?pp_stop ?pp_sep ppf l prints the contents of a list.

\ No newline at end of file diff --git a/dev/containers/CCListLabels/index.html b/dev/containers/CCListLabels/index.html index 9102e295..155fbca8 100644 --- a/dev/containers/CCListLabels/index.html +++ b/dev/containers/CCListLabels/index.html @@ -9,4 +9,4 @@ return @@ x * x;; val square_even : int list -> int list = <fun> # square_even [1;2;4;3;5;2];; -- : int list = [4; 16; 4]
since
3.1
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t

funs <*> l is product (fun f x -> f x) funs l.

val (<$>) : ('a -> 'b) -> 'a t -> 'b t

(<$>) is map.

val return : 'a -> 'a t

return x is x.

val (>>=) : 'a t -> ('a -> 'b t) -> 'b t

l >>= f is flat_map f l.

val take : int -> 'a t -> 'a t

take n l takes the n first elements of the list l, drop the rest.

val drop : int -> 'a t -> 'a t

drop n l drops the n first elements of the list l, keep the rest.

val hd_tl : 'a t -> 'a * 'a t

hd_tl (x :: l) returns hd, l.

raises Failure

if the list is empty.

since
0.16
val take_drop : int -> 'a t -> 'a t * 'a t

take_drop n l returns l1, l2 such that l1 @ l2 = l and length l1 = min (length l) n.

val take_while : f:('a -> bool) -> 'a t -> 'a t

take_while ~f l returns the longest prefix of l for which f is true.

since
0.13
val drop_while : f:('a -> bool) -> 'a t -> 'a t

drop_while ~f l drops the longest prefix of l for which f is true.

since
0.13
val take_drop_while : f:('a -> bool) -> 'a t -> 'a t * 'a t

take_drop_while ~f l = take_while ~f l, drop_while ~f l.

since
1.2, but only
since
2.2 with labels
val last : int -> 'a t -> 'a t

last n l takes the last n elements of l (or less if l doesn't have that many elements).

val head_opt : 'a t -> 'a option

head_opt l returns Some x (the first element of the list l) or None if the list l is empty.

since
0.20
val tail_opt : 'a t -> 'a t option

tail_opt l returns Some l' (the given list l without its first element) or None if the list l is empty.

since
2.0
val last_opt : 'a t -> 'a option

last_opt l returns Some x (the last element of l) or None if the list l is empty.

since
0.20
val find_pred : f:('a -> bool) -> 'a t -> 'a option

find_pred ~f l finds the first element of l that satisfies f, or returns None if no element satisfies f.

since
0.11
val find_opt : f:('a -> bool) -> 'a t -> 'a option

find_opt ~f l is the safe version of find.

since
1.5, but only
since
2.2 with labels
val find_pred_exn : f:('a -> bool) -> 'a t -> 'a

find_pred_exn ~f l is the unsafe version of find_pred.

raises Not_found

if no such element is found.

since
0.11
val find_map : f:('a -> 'b option) -> 'a t -> 'b option

find_map ~f l traverses l, applying f to each element. If for some element x, f x = Some y, then Some y is returned. Otherwise the call returns None.

since
0.11
val find_mapi : f:(int -> 'a -> 'b option) -> 'a t -> 'b option

find_mapi ~f l is like find_map, but also pass the index to the predicate function.

since
0.11
val find_idx : f:('a -> bool) -> 'a t -> (int * 'a) option

find_idx ~f x returns Some (i,x) where x is the i-th element of l, and f x holds. Otherwise returns None.

val remove : eq:('a -> 'a -> bool) -> key:'a -> 'a t -> 'a t

remove ~eq ~key l removes every instance of key from l. Tail-recursive.

parameter eq

equality function.

since
0.11
val filter_map : f:('a -> 'b option) -> 'a t -> 'b t

filter_map ~f l is the sublist of l containing only elements for which f returns Some e. Map and remove elements at the same time.

val keep_some : 'a option t -> 'a t

keep_some l retains only elements of the form Some x. Like filter_map CCFun.id.

since
1.3, but only
since
2.2 with labels
val keep_ok : ('a_) Stdlib.result t -> 'a t

keep_ok l retains only elements of the form Ok x.

since
1.3, but only
since
2.2 with labels
val all_some : 'a option t -> 'a t option

all_some l returns Some l' if all elements of l are of the form Some x, or None otherwise.

since
1.3, but only
since
2.2 with labels
val all_ok : ('a'err) Stdlib.result t -> ('a t'err) Stdlib.result

all_ok l returns Ok l' if all elements of l are of the form Ok x, or Error e otherwise (with the first error met).

since
1.3, but only
since
2.2 with labels
val sorted_mem : cmp:('a -> 'a -> int) -> 'a -> 'a list -> bool

sorted_mem ~cmp x l and mem x l give the same result for any sorted list l, but potentially more efficiently.

since
NEXT_RELEASE
val sorted_merge : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list

sorted_merge ~cmp l1 l2 merges elements from both sorted list using the given comparison function cmp.

val sorted_diff : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list

sorted_diff ~cmp l1 l2 returns the elements in l1 that are not in l2. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff ~cmp [1;1;1;2;2;3] [1;2;2] would be [1;1;3]. It is the left inverse of sorted_merge; that is, sorted_diff ~cmp (sorted_merge ~cmp l1 l2) l2 is always equal to l1 for sorted lists l1 and l2.

since
NEXT_RELEASE
val sort_uniq : cmp:('a -> 'a -> int) -> 'a list -> 'a list

sort_uniq ~cmp l sorts the list l using the given comparison function cmp and remove duplicate elements.

val sorted_merge_uniq : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list

sorted_merge_uniq ~cmp l1 l2 merges the sorted lists l1 and l2 and removes duplicates.

since
0.10
val sorted_diff_uniq : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list

sorted_diff_uniq ~cmp l1 l2 collects the elements in l1 that are not in l2 and then remove duplicates. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff_uniq ~cmp [1;1;1;2;2] [1;2;2;2] would be [1]. sorted_diff_uniq ~cmp l1 l2 and uniq_succ ~eq (sorted_diff ~cmp l1 l2) always give the same result for sorted l1 and l2 and compatible cmp and eq.

since
NEXT_RELEASE
val is_sorted : cmp:('a -> 'a -> int) -> 'a list -> bool

is_sorted ~cmp l returns true iff l is sorted (according to given order).

parameter cmp

the comparison function.

since
0.17
val sorted_insert : cmp:('a -> 'a -> int) -> ?⁠uniq:bool -> 'a -> 'a list -> 'a list

sorted_insert ~cmp ?uniq x l inserts x into l such that, if l was sorted, then sorted_insert x l is sorted too.

parameter uniq

if true and x is already in sorted position in l, then x is not duplicated. Default false (x will be inserted in any case).

since
0.17
val sorted_remove : cmp:('a -> 'a -> int) -> ?⁠all:bool -> 'a -> 'a list -> 'a list

sorted_remove ~cmp x l removes x from a sorted list l such that the return value is sorted too. By default, it is the left inverse of sorted_insert; that is, sorted_remove ~cmp x (sorted_insert ~cmp x l) is equal to l for any sorted list l.

parameter all

if true then all occurrences of x will be removed. Otherwise, only the first x will be removed (if any). Default false (only the first will be removed).

since
NEXT_RELEASE
val uniq_succ : eq:('a -> 'a -> bool) -> 'a list -> 'a list

uniq_succ ~eq l removes duplicate elements that occur one next to the other. Examples: uniq_succ [1;2;1] = [1;2;1]. uniq_succ [1;1;2] = [1;2].

since
0.10
val group_succ : eq:('a -> 'a -> bool) -> 'a list -> 'a list list

group_succ ~eq l groups together consecutive elements that are equal according to eq.

since
0.11

Indices

val mapi : f:(int -> 'a -> 'b) -> 'a t -> 'b t

mapi ~f l is like map, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.

val iteri : f:(int -> 'a -> unit) -> 'a t -> unit

iteri ~f l is like iter, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.

val iteri2 : f:(int -> 'a -> 'b -> unit) -> 'a t -> 'b t -> unit

iteri2 ~f l1 l2 applies f to the two lists l1 and l2 simultaneously. The integer passed to f indicates the index of element.

raises Invalid_argument

when lists do not have the same length.

since
2.0, but only
since
2.2 with labels
val foldi : f:('b -> int -> 'a -> 'b) -> init:'b -> 'a t -> 'b

foldi ~f ~init l is like fold but it also passes in the index of each element, from 0 to length l - 1 as additional argument to the folded function f. Tail-recursive.

val foldi2 : f:('c -> int -> 'a -> 'b -> 'c) -> init:'c -> 'a t -> 'b t -> 'c

foldi2 ~f ~init l1 l2 folds on the two lists l1 and l2, with index of each element passed to the function f. Computes f(… (f init i_0 l1_0 l2_0) …) i_n l1_n l2_n .

raises Invalid_argument

when lists do not have the same length.

since
2.0, but only
since
2.2 with labels
val get_at_idx : int -> 'a t -> 'a option

get_at_idx i l returns Some i-th element of the given list l or None if the list l is too short. If the index is negative, it will get element starting from the end of the list l.

val nth_opt : 'a t -> int -> 'a option

nth_opt l n returns Some n-th element of l. Safe version of nth.

raises Invalid_argument

if the int is negative.

since
1.5, but only
since
2.2 with labels
val get_at_idx_exn : int -> 'a t -> 'a

get_at_idx_exn i l gets the i-th element of l, or

raises Not_found

if the index is invalid. The first element has index 0. If the index is negative, it will get element starting from the end of the list.

val set_at_idx : int -> 'a -> 'a t -> 'a t

set_at_idx i x l replaces the i-th element with x (removes the old one), or does nothing if index is too high. If the index is negative, it will set element starting from the end of the list.

val insert_at_idx : int -> 'a -> 'a t -> 'a t

insert_at_idx i x l inserts x at i-th position, between the two existing elements. If the index is too high, append at the end of the list. If the index is negative, it will insert element starting from the end of the list.

val remove_at_idx : int -> 'a t -> 'a t

remove_at_idx i l removes element at given index i. Does nothing if the index is too high. If the index is negative, it will remove element starting from the end of the list.

Set Operators

Those operations maintain the invariant that the list does not contain duplicates (if it already satisfies it).

val add_nodup : eq:('a -> 'a -> bool) -> 'a -> 'a t -> 'a t

add_nodup ~eq x set adds x to set if it was not already present. Linear time.

since
0.11
val remove_one : eq:('a -> 'a -> bool) -> 'a -> 'a t -> 'a t

remove_one ~eq x set removes one occurrence of x from set. Linear time.

since
0.11
val mem : ?⁠eq:('a -> 'a -> bool) -> 'a -> 'a t -> bool

mem ?eq x l is true iff x is equal to an element of l. A comparator function eq can be provided. Linear time.

val subset : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> bool

subset ~eq l1 l2 tests if all elements of the list l1 are contained in the list l2 by applying eq.

val uniq : eq:('a -> 'a -> bool) -> 'a t -> 'a t

uniq ~eq l removes duplicates in l w.r.t the equality predicate eq. Complexity is quadratic in the length of the list, but the order of elements is preserved. If you wish for a faster de-duplication but do not care about the order, use sort_uniq.

val union : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> 'a t

union ~eq l1 l2 is the union of the lists l1 and l2 w.r.t. the equality predicate eq. Complexity is product of length of inputs.

val inter : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> 'a t

inter ~eq l1 l2 is the intersection of the lists l1 and l2 w.r.t. the equality predicate eq. Complexity is product of length of inputs.

Other Constructors

val range_by : step:int -> int -> int -> int t

range_by ~step i j iterates on integers from i to j included, where the difference between successive elements is step. Use a negative step for a decreasing list.

raises Invalid_argument

if step=0.

since
0.18
val range : int -> int -> int t

range i j iterates on integers from i to j included. It works both for decreasing and increasing ranges.

val range' : int -> int -> int t

range' i j is like range but the second bound j is excluded. For instance range' 0 5 = [0;1;2;3;4].

val (--) : int -> int -> int t

i -- j is the list of integers from i to j included. Infix alias for range.

val (--^) : int -> int -> int t

i --^ j is the list of integers from i to j excluded. Infix alias for range'.

since
0.17
val replicate : int -> 'a -> 'a t

replicate n x replicates the given element x n times.

val repeat : int -> 'a t -> 'a t

repeat n l concatenates the list l with itself n times.

Association Lists

module Assoc : sig ... end
val assoc : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'b

assoc ~eq k alist returns the value v associated with key k in alist. Like Assoc.get_exn.

since
2.0
val assoc_opt : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'b option

assoc_opt ~eq k alist returns Some v if the given key k is present into alist, or None if not present. Like Assoc.get.

since
1.5, but only
since
2.0 with labels
val assq_opt : 'a -> ('a * 'b) t -> 'b option

assq_opt k alist returns Some v if the given key k is present into alist. Like Assoc.assoc_opt but use physical equality instead of structural equality to compare keys. Safe version of assq.

since
1.5, but only
since
2.0 with labels
val mem_assoc : ?⁠eq:('a -> 'a -> bool) -> 'a -> ('a * _) t -> bool

mem_assoc ?eq k alist returns true iff k is a key in alist. Like Assoc.mem.

since
2.0
val remove_assoc : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> ('a * 'b) t

remove_assoc ~eq k alist returns the alist without the first pair with key k, if any. Like Assoc.remove.

since
2.0

References on Lists

since
0.3.3
module Ref : sig ... end
module type MONAD = sig ... end
module Traverse : functor (M : MONAD) -> sig ... end

Conversions

val random : 'a random_gen -> 'a t random_gen
val random_non_empty : 'a random_gen -> 'a t random_gen
val random_len : int -> 'a random_gen -> 'a t random_gen
val random_choose : 'a t -> 'a random_gen

random_choose l randomly chooses an element in the list l.

raises Not_found

if the list is empty.

val random_sequence : 'a random_gen t -> 'a t random_gen
val to_string : ?⁠start:string -> ?⁠stop:string -> ?⁠sep:string -> ('a -> string) -> 'a t -> string

to_string ?start ?stop ?sep item_to_string l print l to a string using sep as a separator between elements of l.

since
2.7
val to_iter : 'a t -> 'a iter

to_iter l returns a iter of the elements of the list l.

since
2.8
val to_seq : 'a t -> 'a Stdlib.Seq.t

to_seq l returns a Seq.t of the elements of the list l. Renamed from to_std_seq since 3.0.

since
3.0
val of_iter : 'a iter -> 'a t

of_iter iter builds a list from a given iter. In the result, elements appear in the same order as they did in the source iter.

since
2.8
val of_seq_rev : 'a Stdlib.Seq.t -> 'a t

of_seq_rev seq builds a list from a given Seq.t, in reverse order. Renamed from of_std_seq_rev since 3.0.

since
3.0
val of_seq : 'a Stdlib.Seq.t -> 'a t

of_seq seq builds a list from a given Seq.t. In the result, elements appear in the same order as they did in the source Seq.t. Renamed from of_std_seq since 3.0.

since
3.0
val to_gen : 'a t -> 'a gen

to_gen l returns a gen of the elements of the list l.

val of_gen : 'a gen -> 'a t

of_gen gen builds a list from a given gen. In the result, elements appear in the same order as they did in the source gen.

Infix Operators

It is convenient to open CCList.Infix to access the infix operators without cluttering the scope too much.

since
0.16
module Infix : sig ... end

Let operators on OCaml >= 4.08.0, nothing otherwise

since
2.8
include CCShimsMkLet_.S with type 'a t_let := 'a list
type 'a t_let
val let+ : 'a t_let -> ('a -> 'b) -> 'b t_let
val and+ : 'a t_let -> 'b t_let -> ('a * 'b) t_let
val let* : 'a t_let -> ('a -> 'b t_let) -> 'b t_let
val and* : 'a t_let -> 'b t_let -> ('a * 'b) t_let

IO

val pp : ?⁠pp_start:unit printer -> ?⁠pp_stop:unit printer -> ?⁠pp_sep:unit printer -> 'a printer -> 'a t printer

pp ?pp_start ?pp_stop ?pp_sep ppf l prints the contents of a list.

\ No newline at end of file +- : int list = [4; 16; 4]
since
3.1
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t

funs <*> l is product (fun f x -> f x) funs l.

val (<$>) : ('a -> 'b) -> 'a t -> 'b t

(<$>) is map.

val return : 'a -> 'a t

return x is x.

val (>>=) : 'a t -> ('a -> 'b t) -> 'b t

l >>= f is flat_map f l.

val take : int -> 'a t -> 'a t

take n l takes the n first elements of the list l, drop the rest.

val drop : int -> 'a t -> 'a t

drop n l drops the n first elements of the list l, keep the rest.

val hd_tl : 'a t -> 'a * 'a t

hd_tl (x :: l) returns hd, l.

raises Failure

if the list is empty.

since
0.16
val take_drop : int -> 'a t -> 'a t * 'a t

take_drop n l returns l1, l2 such that l1 @ l2 = l and length l1 = min (length l) n.

val take_while : f:('a -> bool) -> 'a t -> 'a t

take_while ~f l returns the longest prefix of l for which f is true.

since
0.13
val drop_while : f:('a -> bool) -> 'a t -> 'a t

drop_while ~f l drops the longest prefix of l for which f is true.

since
0.13
val take_drop_while : f:('a -> bool) -> 'a t -> 'a t * 'a t

take_drop_while ~f l = take_while ~f l, drop_while ~f l.

since
1.2, but only
since
2.2 with labels
val last : int -> 'a t -> 'a t

last n l takes the last n elements of l (or less if l doesn't have that many elements).

val head_opt : 'a t -> 'a option

head_opt l returns Some x (the first element of the list l) or None if the list l is empty.

since
0.20
val tail_opt : 'a t -> 'a t option

tail_opt l returns Some l' (the given list l without its first element) or None if the list l is empty.

since
2.0
val last_opt : 'a t -> 'a option

last_opt l returns Some x (the last element of l) or None if the list l is empty.

since
0.20
val find_pred : f:('a -> bool) -> 'a t -> 'a option

find_pred ~f l finds the first element of l that satisfies f, or returns None if no element satisfies f.

since
0.11
val find_opt : f:('a -> bool) -> 'a t -> 'a option

find_opt ~f l is the safe version of find.

since
1.5, but only
since
2.2 with labels
val find_pred_exn : f:('a -> bool) -> 'a t -> 'a

find_pred_exn ~f l is the unsafe version of find_pred.

raises Not_found

if no such element is found.

since
0.11
val find_map : f:('a -> 'b option) -> 'a t -> 'b option

find_map ~f l traverses l, applying f to each element. If for some element x, f x = Some y, then Some y is returned. Otherwise the call returns None.

since
0.11
val find_mapi : f:(int -> 'a -> 'b option) -> 'a t -> 'b option

find_mapi ~f l is like find_map, but also pass the index to the predicate function.

since
0.11
val find_idx : f:('a -> bool) -> 'a t -> (int * 'a) option

find_idx ~f x returns Some (i,x) where x is the i-th element of l, and f x holds. Otherwise returns None.

val remove : eq:('a -> 'a -> bool) -> key:'a -> 'a t -> 'a t

remove ~eq ~key l removes every instance of key from l. Tail-recursive.

parameter eq

equality function.

since
0.11
val filter_map : f:('a -> 'b option) -> 'a t -> 'b t

filter_map ~f l is the sublist of l containing only elements for which f returns Some e. Map and remove elements at the same time.

val keep_some : 'a option t -> 'a t

keep_some l retains only elements of the form Some x. Like filter_map CCFun.id.

since
1.3, but only
since
2.2 with labels
val keep_ok : ('a_) Stdlib.result t -> 'a t

keep_ok l retains only elements of the form Ok x.

since
1.3, but only
since
2.2 with labels
val all_some : 'a option t -> 'a t option

all_some l returns Some l' if all elements of l are of the form Some x, or None otherwise.

since
1.3, but only
since
2.2 with labels
val all_ok : ('a'err) Stdlib.result t -> ('a t'err) Stdlib.result

all_ok l returns Ok l' if all elements of l are of the form Ok x, or Error e otherwise (with the first error met).

since
1.3, but only
since
2.2 with labels
val sorted_mem : cmp:('a -> 'a -> int) -> 'a -> 'a list -> bool

sorted_mem ~cmp x l and mem x l give the same result for any sorted list l, but potentially more efficiently.

since
3.5
val sorted_merge : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list

sorted_merge ~cmp l1 l2 merges elements from both sorted list using the given comparison function cmp.

val sorted_diff : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list

sorted_diff ~cmp l1 l2 returns the elements in l1 that are not in l2. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff ~cmp [1;1;1;2;2;3] [1;2;2] would be [1;1;3]. It is the left inverse of sorted_merge; that is, sorted_diff ~cmp (sorted_merge ~cmp l1 l2) l2 is always equal to l1 for sorted lists l1 and l2.

since
3.5
val sort_uniq : cmp:('a -> 'a -> int) -> 'a list -> 'a list

sort_uniq ~cmp l sorts the list l using the given comparison function cmp and remove duplicate elements.

val sorted_merge_uniq : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list

sorted_merge_uniq ~cmp l1 l2 merges the sorted lists l1 and l2 and removes duplicates.

since
0.10
val sorted_diff_uniq : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list

sorted_diff_uniq ~cmp l1 l2 collects the elements in l1 that are not in l2 and then remove duplicates. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff_uniq ~cmp [1;1;1;2;2] [1;2;2;2] would be [1]. sorted_diff_uniq ~cmp l1 l2 and uniq_succ ~eq (sorted_diff ~cmp l1 l2) always give the same result for sorted l1 and l2 and compatible cmp and eq.

since
3.5
val is_sorted : cmp:('a -> 'a -> int) -> 'a list -> bool

is_sorted ~cmp l returns true iff l is sorted (according to given order).

parameter cmp

the comparison function.

since
0.17
val sorted_insert : cmp:('a -> 'a -> int) -> ?⁠uniq:bool -> 'a -> 'a list -> 'a list

sorted_insert ~cmp ?uniq x l inserts x into l such that, if l was sorted, then sorted_insert x l is sorted too.

parameter uniq

if true and x is already in sorted position in l, then x is not duplicated. Default false (x will be inserted in any case).

since
0.17
val sorted_remove : cmp:('a -> 'a -> int) -> ?⁠all:bool -> 'a -> 'a list -> 'a list

sorted_remove ~cmp x l removes x from a sorted list l such that the return value is sorted too. By default, it is the left inverse of sorted_insert; that is, sorted_remove ~cmp x (sorted_insert ~cmp x l) is equal to l for any sorted list l.

parameter all

if true then all occurrences of x will be removed. Otherwise, only the first x will be removed (if any). Default false (only the first will be removed).

since
3.5
val uniq_succ : eq:('a -> 'a -> bool) -> 'a list -> 'a list

uniq_succ ~eq l removes duplicate elements that occur one next to the other. Examples: uniq_succ [1;2;1] = [1;2;1]. uniq_succ [1;1;2] = [1;2].

since
0.10
val group_succ : eq:('a -> 'a -> bool) -> 'a list -> 'a list list

group_succ ~eq l groups together consecutive elements that are equal according to eq.

since
0.11

Indices

val mapi : f:(int -> 'a -> 'b) -> 'a t -> 'b t

mapi ~f l is like map, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.

val iteri : f:(int -> 'a -> unit) -> 'a t -> unit

iteri ~f l is like iter, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.

val iteri2 : f:(int -> 'a -> 'b -> unit) -> 'a t -> 'b t -> unit

iteri2 ~f l1 l2 applies f to the two lists l1 and l2 simultaneously. The integer passed to f indicates the index of element.

raises Invalid_argument

when lists do not have the same length.

since
2.0, but only
since
2.2 with labels
val foldi : f:('b -> int -> 'a -> 'b) -> init:'b -> 'a t -> 'b

foldi ~f ~init l is like fold but it also passes in the index of each element, from 0 to length l - 1 as additional argument to the folded function f. Tail-recursive.

val foldi2 : f:('c -> int -> 'a -> 'b -> 'c) -> init:'c -> 'a t -> 'b t -> 'c

foldi2 ~f ~init l1 l2 folds on the two lists l1 and l2, with index of each element passed to the function f. Computes f(… (f init i_0 l1_0 l2_0) …) i_n l1_n l2_n .

raises Invalid_argument

when lists do not have the same length.

since
2.0, but only
since
2.2 with labels
val get_at_idx : int -> 'a t -> 'a option

get_at_idx i l returns Some i-th element of the given list l or None if the list l is too short. If the index is negative, it will get element starting from the end of the list l.

val nth_opt : 'a t -> int -> 'a option

nth_opt l n returns Some n-th element of l. Safe version of nth.

raises Invalid_argument

if the int is negative.

since
1.5, but only
since
2.2 with labels
val get_at_idx_exn : int -> 'a t -> 'a

get_at_idx_exn i l gets the i-th element of l, or

raises Not_found

if the index is invalid. The first element has index 0. If the index is negative, it will get element starting from the end of the list.

val set_at_idx : int -> 'a -> 'a t -> 'a t

set_at_idx i x l replaces the i-th element with x (removes the old one), or does nothing if index is too high. If the index is negative, it will set element starting from the end of the list.

val insert_at_idx : int -> 'a -> 'a t -> 'a t

insert_at_idx i x l inserts x at i-th position, between the two existing elements. If the index is too high, append at the end of the list. If the index is negative, it will insert element starting from the end of the list.

val remove_at_idx : int -> 'a t -> 'a t

remove_at_idx i l removes element at given index i. Does nothing if the index is too high. If the index is negative, it will remove element starting from the end of the list.

Set Operators

Those operations maintain the invariant that the list does not contain duplicates (if it already satisfies it).

val add_nodup : eq:('a -> 'a -> bool) -> 'a -> 'a t -> 'a t

add_nodup ~eq x set adds x to set if it was not already present. Linear time.

since
0.11
val remove_one : eq:('a -> 'a -> bool) -> 'a -> 'a t -> 'a t

remove_one ~eq x set removes one occurrence of x from set. Linear time.

since
0.11
val mem : ?⁠eq:('a -> 'a -> bool) -> 'a -> 'a t -> bool

mem ?eq x l is true iff x is equal to an element of l. A comparator function eq can be provided. Linear time.

val subset : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> bool

subset ~eq l1 l2 tests if all elements of the list l1 are contained in the list l2 by applying eq.

val uniq : eq:('a -> 'a -> bool) -> 'a t -> 'a t

uniq ~eq l removes duplicates in l w.r.t the equality predicate eq. Complexity is quadratic in the length of the list, but the order of elements is preserved. If you wish for a faster de-duplication but do not care about the order, use sort_uniq.

val union : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> 'a t

union ~eq l1 l2 is the union of the lists l1 and l2 w.r.t. the equality predicate eq. Complexity is product of length of inputs.

val inter : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> 'a t

inter ~eq l1 l2 is the intersection of the lists l1 and l2 w.r.t. the equality predicate eq. Complexity is product of length of inputs.

Other Constructors

val range_by : step:int -> int -> int -> int t

range_by ~step i j iterates on integers from i to j included, where the difference between successive elements is step. Use a negative step for a decreasing list.

raises Invalid_argument

if step=0.

since
0.18
val range : int -> int -> int t

range i j iterates on integers from i to j included. It works both for decreasing and increasing ranges.

val range' : int -> int -> int t

range' i j is like range but the second bound j is excluded. For instance range' 0 5 = [0;1;2;3;4].

val (--) : int -> int -> int t

i -- j is the list of integers from i to j included. Infix alias for range.

val (--^) : int -> int -> int t

i --^ j is the list of integers from i to j excluded. Infix alias for range'.

since
0.17
val replicate : int -> 'a -> 'a t

replicate n x replicates the given element x n times.

val repeat : int -> 'a t -> 'a t

repeat n l concatenates the list l with itself n times.

Association Lists

module Assoc : sig ... end
val assoc : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'b

assoc ~eq k alist returns the value v associated with key k in alist. Like Assoc.get_exn.

since
2.0
val assoc_opt : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'b option

assoc_opt ~eq k alist returns Some v if the given key k is present into alist, or None if not present. Like Assoc.get.

since
1.5, but only
since
2.0 with labels
val assq_opt : 'a -> ('a * 'b) t -> 'b option

assq_opt k alist returns Some v if the given key k is present into alist. Like Assoc.assoc_opt but use physical equality instead of structural equality to compare keys. Safe version of assq.

since
1.5, but only
since
2.0 with labels
val mem_assoc : ?⁠eq:('a -> 'a -> bool) -> 'a -> ('a * _) t -> bool

mem_assoc ?eq k alist returns true iff k is a key in alist. Like Assoc.mem.

since
2.0
val remove_assoc : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> ('a * 'b) t

remove_assoc ~eq k alist returns the alist without the first pair with key k, if any. Like Assoc.remove.

since
2.0

References on Lists

since
0.3.3
module Ref : sig ... end
module type MONAD = sig ... end
module Traverse : functor (M : MONAD) -> sig ... end

Conversions

val random : 'a random_gen -> 'a t random_gen
val random_non_empty : 'a random_gen -> 'a t random_gen
val random_len : int -> 'a random_gen -> 'a t random_gen
val random_choose : 'a t -> 'a random_gen

random_choose l randomly chooses an element in the list l.

raises Not_found

if the list is empty.

val random_sequence : 'a random_gen t -> 'a t random_gen
val to_string : ?⁠start:string -> ?⁠stop:string -> ?⁠sep:string -> ('a -> string) -> 'a t -> string

to_string ?start ?stop ?sep item_to_string l print l to a string using sep as a separator between elements of l.

since
2.7
val to_iter : 'a t -> 'a iter

to_iter l returns a iter of the elements of the list l.

since
2.8
val to_seq : 'a t -> 'a Stdlib.Seq.t

to_seq l returns a Seq.t of the elements of the list l. Renamed from to_std_seq since 3.0.

since
3.0
val of_iter : 'a iter -> 'a t

of_iter iter builds a list from a given iter. In the result, elements appear in the same order as they did in the source iter.

since
2.8
val of_seq_rev : 'a Stdlib.Seq.t -> 'a t

of_seq_rev seq builds a list from a given Seq.t, in reverse order. Renamed from of_std_seq_rev since 3.0.

since
3.0
val of_seq : 'a Stdlib.Seq.t -> 'a t

of_seq seq builds a list from a given Seq.t. In the result, elements appear in the same order as they did in the source Seq.t. Renamed from of_std_seq since 3.0.

since
3.0
val to_gen : 'a t -> 'a gen

to_gen l returns a gen of the elements of the list l.

val of_gen : 'a gen -> 'a t

of_gen gen builds a list from a given gen. In the result, elements appear in the same order as they did in the source gen.

Infix Operators

It is convenient to open CCList.Infix to access the infix operators without cluttering the scope too much.

since
0.16
module Infix : sig ... end

Let operators on OCaml >= 4.08.0, nothing otherwise

since
2.8
include CCShimsMkLet_.S with type 'a t_let := 'a list
type 'a t_let
val let+ : 'a t_let -> ('a -> 'b) -> 'b t_let
val and+ : 'a t_let -> 'b t_let -> ('a * 'b) t_let
val let* : 'a t_let -> ('a -> 'b t_let) -> 'b t_let
val and* : 'a t_let -> 'b t_let -> ('a * 'b) t_let

IO

val pp : ?⁠pp_start:unit printer -> ?⁠pp_stop:unit printer -> ?⁠pp_sep:unit printer -> 'a printer -> 'a t printer

pp ?pp_start ?pp_stop ?pp_sep ppf l prints the contents of a list.

\ No newline at end of file diff --git a/dev/containers/CCOpt/index.html b/dev/containers/CCOpt/index.html index 9ea35516..92371ffd 100644 --- a/dev/containers/CCOpt/index.html +++ b/dev/containers/CCOpt/index.html @@ -1,2 +1,2 @@ -CCOpt (containers.CCOpt)

Module CCOpt

Options

type +'a t = 'a option
val map : ('a -> 'b) -> 'a t -> 'b t

map f o applies the function f to the element inside o, if any.

val map_or : default:'b -> ('a -> 'b) -> 'a t -> 'b

map_or ~default f o is f x if o = Some x, default otherwise.

since
0.16
val map_lazy : (unit -> 'b) -> ('a -> 'b) -> 'a t -> 'b

map_lazy default_fn f o if f o if o = Some x, default_fn () otherwise.

since
1.2
val is_some : _ t -> bool

is_some (Some x) returns true otherwise it returns false.

val is_none : _ t -> bool

is_none None returns true otherwise it returns false.

since
0.11
val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int

compare comp o1 o2 compares two options o1 and o2, using custom comparators comp for the value. None is always assumed to be less than Some _.

val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool

equal p o1 o2 tests for equality between option types o1 and o2, using a custom equality predicate p.

val return : 'a -> 'a t

return x is a monadic return, that is return x = Some x.

val some : 'a -> 'a t

Alias to return.

since
NEXT_RELEASE
val none : 'a t

Alias to None.

since
NEXT_RELEASE
val (>|=) : 'a t -> ('a -> 'b) -> 'b t

o >|= f is the infix version of map.

val flat_map : ('a -> 'b t) -> 'a t -> 'b t

flat_map f o is equivalent to map followed by flatten. Flip version of >>=.

val bind : 'a t -> ('a -> 'b t) -> 'b t

bind o f is f v if o is Some v, None otherwise. Monadic bind.

since
3.0
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t

o >>= f is the infix version of bind.

val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t

map2 f o1 o2 maps 'a option and 'b option to a 'c option using f.

val iter : ('a -> unit) -> 'a t -> unit

iter f o applies f to o. Iterate on 0 or 1 element.

val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a

fold f init o is f init x if o is Some x, or init if o is None. Fold on 0 or 1 element.

val filter : ('a -> bool) -> 'a t -> 'a t

filter f o returns Some x if o is Some x and f x is true, or None if f x is false or if o is None. Filter on 0 or 1 element.

since
0.5
val if_ : ('a -> bool) -> 'a -> 'a option

if_ f x is Some x if f x, None otherwise.

since
0.17
val exists : ('a -> bool) -> 'a t -> bool

exists f o returns true iff there exists an element for which the provided function f evaluates to true.

since
0.17
val for_all : ('a -> bool) -> 'a t -> bool

for_all f o returns true iff the provided function f evaluates to true for all elements.

since
0.17
val get_or : default:'a -> 'a t -> 'a

get_or ~default o extracts the value from o, or returns default if o is None.

since
0.18
val value : 'a t -> default:'a -> 'a

value o ~default is similar to the Stdlib's Option.value and to get_or.

since
2.8
val get_exn : 'a t -> 'a

get_exn o returns x if o is Some x or fails if o is None.

raises Invalid_argument

if the option is None.

deprecated

use get_exn_or instead

val get_exn_or : string -> 'a t -> 'a

get_exn_or msg o returns x if o is Some x or fails with Invalid_argument msg if o is None.

raises Invalid_argument

if the option is None.

since
3.4
val get_lazy : (unit -> 'a) -> 'a t -> 'a

get_lazy default_fn o unwraps o, but if o is None it returns default_fn () instead.

since
0.6.1
val sequence_l : 'a t list -> 'a list t

sequence_l [x1; x2; …; xn] returns Some [y1; y2; …; yn] if every xi is Some yi. Otherwise, if the list contains at least one None, the result is None.

val wrap : ?⁠handler:(exn -> bool) -> ('a -> 'b) -> 'a -> 'b option

wrap ?handler f x calls f x and returns Some y if f x = y. If f x raises any exception, the result is None. This can be useful to wrap functions such as Map.S.find.

parameter handler

the exception handler, which returns true if the exception is to be caught.

val wrap2 : ?⁠handler:(exn -> bool) -> ('a -> 'b -> 'c) -> 'a -> 'b -> 'c option

wrap2 ?handler f x y is similar to wrap but for binary functions.

Applicative

val pure : 'a -> 'a t

pure x is an alias to return.

val (<*>) : ('a -> 'b) t -> 'a t -> 'b t

f <*> (Some x) returns Some (f x) and f <*> None returns None.

val (<$>) : ('a -> 'b) -> 'a t -> 'b t

f <$> o is like map f o.

Alternatives

val or_ : else_:'a t -> 'a t -> 'a t

or_ ~else_ o is o if o is Some _, else_ if o is None.

since
1.2
val or_lazy : else_:(unit -> 'a t) -> 'a t -> 'a t

or_lazy ~else_ o is o if o is Some _, else_ () if o is None.

since
1.2
val (<+>) : 'a t -> 'a t -> 'a t

o1 <+> o2 is o1 if o1 is Some _, o2 if o1 is None.

val choice : 'a t list -> 'a t

choice lo returns the first non-None element of the list lo, or None.

val flatten : 'a t t -> 'a t

flatten oo transforms Some x into x.

since
2.2
val return_if : bool -> 'a -> 'a t

return_if b x applies Some or None depending on the boolean b. More precisely, return_if false x is None, and return_if true x is Some x.

since
2.2

Infix Operators

since
0.16
module Infix : sig ... end

Let operators on OCaml >= 4.08.0, nothing otherwise

since
2.8
include CCShimsMkLet_.S with type 'a t_let := 'a option
type 'a t_let
val let+ : 'a t_let -> ('a -> 'b) -> 'b t_let
val and+ : 'a t_let -> 'b t_let -> ('a * 'b) t_let
val let* : 'a t_let -> ('a -> 'b t_let) -> 'b t_let
val and* : 'a t_let -> 'b t_let -> ('a * 'b) t_let

Conversion and IO

val to_list : 'a t -> 'a list

to_list o returns [x] if o is Some x or the empty list [] if o is None.

val of_list : 'a list -> 'a t

of_list l returns Some x (x being the head of the list l), or None if l is the empty list.

val to_result : 'e -> 'a t -> ('a'e) Stdlib.result

to_result e o returns Ok x if o is Some x, or Error e if o is None.

since
1.2
val to_result_lazy : (unit -> 'e) -> 'a t -> ('a'e) Stdlib.result

to_result_lazy f o returns Ok x if o is Some x or Error f if o is None.

since
1.2
val of_result : ('a_) Stdlib.result -> 'a t

of_result result returns an option from a result.

since
1.2
type 'a iter = ('a -> unit) -> unit
type 'a gen = unit -> 'a option
type 'a printer = Stdlib.Format.formatter -> 'a -> unit
type 'a random_gen = Stdlib.Random.State.t -> 'a
val random : 'a random_gen -> 'a t random_gen
val choice_iter : 'a t iter -> 'a t

choice_iter iter is similar to choice, but works on iter. It returns the first Some x occurring in iter, or None otherwise.

since
3.0
val choice_seq : 'a t Stdlib.Seq.t -> 'a t

choice_seq seq works on Seq.t. It returns the first Some x occurring in seq, or None otherwise.

since
3.0
val to_gen : 'a t -> 'a gen

to_gen o is o as a gen. Some x is the singleton gen containing x and None is the empty gen.

val to_seq : 'a t -> 'a Stdlib.Seq.t

to_seq o is o as a sequence Seq.t. Some x is the singleton sequence containing x and None is the empty sequence. Same as Stdlib.Option.to_seq Renamed from to_std_seq since 3.0.

since
3.0
val to_iter : 'a t -> 'a iter

to_iter o returns an internal iterator, like in the library Iter.

since
2.8
val pp : 'a printer -> 'a t printer

pp ppf o pretty-prints option o using ppf.

\ No newline at end of file +CCOpt (containers.CCOpt)

Module CCOpt

Options

type +'a t = 'a option
val map : ('a -> 'b) -> 'a t -> 'b t

map f o applies the function f to the element inside o, if any.

val map_or : default:'b -> ('a -> 'b) -> 'a t -> 'b

map_or ~default f o is f x if o = Some x, default otherwise.

since
0.16
val map_lazy : (unit -> 'b) -> ('a -> 'b) -> 'a t -> 'b

map_lazy default_fn f o if f o if o = Some x, default_fn () otherwise.

since
1.2
val is_some : _ t -> bool

is_some (Some x) returns true otherwise it returns false.

val is_none : _ t -> bool

is_none None returns true otherwise it returns false.

since
0.11
val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int

compare comp o1 o2 compares two options o1 and o2, using custom comparators comp for the value. None is always assumed to be less than Some _.

val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool

equal p o1 o2 tests for equality between option types o1 and o2, using a custom equality predicate p.

val return : 'a -> 'a t

return x is a monadic return, that is return x = Some x.

val some : 'a -> 'a t

Alias to return.

since
3.5
val none : 'a t

Alias to None.

since
3.5
val (>|=) : 'a t -> ('a -> 'b) -> 'b t

o >|= f is the infix version of map.

val flat_map : ('a -> 'b t) -> 'a t -> 'b t

flat_map f o is equivalent to map followed by flatten. Flip version of >>=.

val bind : 'a t -> ('a -> 'b t) -> 'b t

bind o f is f v if o is Some v, None otherwise. Monadic bind.

since
3.0
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t

o >>= f is the infix version of bind.

val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t

map2 f o1 o2 maps 'a option and 'b option to a 'c option using f.

val iter : ('a -> unit) -> 'a t -> unit

iter f o applies f to o. Iterate on 0 or 1 element.

val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a

fold f init o is f init x if o is Some x, or init if o is None. Fold on 0 or 1 element.

val filter : ('a -> bool) -> 'a t -> 'a t

filter f o returns Some x if o is Some x and f x is true, or None if f x is false or if o is None. Filter on 0 or 1 element.

since
0.5
val if_ : ('a -> bool) -> 'a -> 'a option

if_ f x is Some x if f x, None otherwise.

since
0.17
val exists : ('a -> bool) -> 'a t -> bool

exists f o returns true iff there exists an element for which the provided function f evaluates to true.

since
0.17
val for_all : ('a -> bool) -> 'a t -> bool

for_all f o returns true iff the provided function f evaluates to true for all elements.

since
0.17
val get_or : default:'a -> 'a t -> 'a

get_or ~default o extracts the value from o, or returns default if o is None.

since
0.18
val value : 'a t -> default:'a -> 'a

value o ~default is similar to the Stdlib's Option.value and to get_or.

since
2.8
val get_exn : 'a t -> 'a

get_exn o returns x if o is Some x or fails if o is None.

raises Invalid_argument

if the option is None.

deprecated

use get_exn_or instead

val get_exn_or : string -> 'a t -> 'a

get_exn_or msg o returns x if o is Some x or fails with Invalid_argument msg if o is None.

raises Invalid_argument

if the option is None.

since
3.4
val get_lazy : (unit -> 'a) -> 'a t -> 'a

get_lazy default_fn o unwraps o, but if o is None it returns default_fn () instead.

since
0.6.1
val sequence_l : 'a t list -> 'a list t

sequence_l [x1; x2; …; xn] returns Some [y1; y2; …; yn] if every xi is Some yi. Otherwise, if the list contains at least one None, the result is None.

val wrap : ?⁠handler:(exn -> bool) -> ('a -> 'b) -> 'a -> 'b option

wrap ?handler f x calls f x and returns Some y if f x = y. If f x raises any exception, the result is None. This can be useful to wrap functions such as Map.S.find.

parameter handler

the exception handler, which returns true if the exception is to be caught.

val wrap2 : ?⁠handler:(exn -> bool) -> ('a -> 'b -> 'c) -> 'a -> 'b -> 'c option

wrap2 ?handler f x y is similar to wrap but for binary functions.

Applicative

val pure : 'a -> 'a t

pure x is an alias to return.

val (<*>) : ('a -> 'b) t -> 'a t -> 'b t

f <*> (Some x) returns Some (f x) and f <*> None returns None.

val (<$>) : ('a -> 'b) -> 'a t -> 'b t

f <$> o is like map f o.

Alternatives

val or_ : else_:'a t -> 'a t -> 'a t

or_ ~else_ o is o if o is Some _, else_ if o is None.

since
1.2
val or_lazy : else_:(unit -> 'a t) -> 'a t -> 'a t

or_lazy ~else_ o is o if o is Some _, else_ () if o is None.

since
1.2
val (<+>) : 'a t -> 'a t -> 'a t

o1 <+> o2 is o1 if o1 is Some _, o2 if o1 is None.

val choice : 'a t list -> 'a t

choice lo returns the first non-None element of the list lo, or None.

val flatten : 'a t t -> 'a t

flatten oo transforms Some x into x.

since
2.2
val return_if : bool -> 'a -> 'a t

return_if b x applies Some or None depending on the boolean b. More precisely, return_if false x is None, and return_if true x is Some x.

since
2.2

Infix Operators

since
0.16
module Infix : sig ... end

Let operators on OCaml >= 4.08.0, nothing otherwise

since
2.8
include CCShimsMkLet_.S with type 'a t_let := 'a option
type 'a t_let
val let+ : 'a t_let -> ('a -> 'b) -> 'b t_let
val and+ : 'a t_let -> 'b t_let -> ('a * 'b) t_let
val let* : 'a t_let -> ('a -> 'b t_let) -> 'b t_let
val and* : 'a t_let -> 'b t_let -> ('a * 'b) t_let

Conversion and IO

val to_list : 'a t -> 'a list

to_list o returns [x] if o is Some x or the empty list [] if o is None.

val of_list : 'a list -> 'a t

of_list l returns Some x (x being the head of the list l), or None if l is the empty list.

val to_result : 'e -> 'a t -> ('a'e) Stdlib.result

to_result e o returns Ok x if o is Some x, or Error e if o is None.

since
1.2
val to_result_lazy : (unit -> 'e) -> 'a t -> ('a'e) Stdlib.result

to_result_lazy f o returns Ok x if o is Some x or Error f if o is None.

since
1.2
val of_result : ('a_) Stdlib.result -> 'a t

of_result result returns an option from a result.

since
1.2
type 'a iter = ('a -> unit) -> unit
type 'a gen = unit -> 'a option
type 'a printer = Stdlib.Format.formatter -> 'a -> unit
type 'a random_gen = Stdlib.Random.State.t -> 'a
val random : 'a random_gen -> 'a t random_gen
val choice_iter : 'a t iter -> 'a t

choice_iter iter is similar to choice, but works on iter. It returns the first Some x occurring in iter, or None otherwise.

since
3.0
val choice_seq : 'a t Stdlib.Seq.t -> 'a t

choice_seq seq works on Seq.t. It returns the first Some x occurring in seq, or None otherwise.

since
3.0
val to_gen : 'a t -> 'a gen

to_gen o is o as a gen. Some x is the singleton gen containing x and None is the empty gen.

val to_seq : 'a t -> 'a Stdlib.Seq.t

to_seq o is o as a sequence Seq.t. Some x is the singleton sequence containing x and None is the empty sequence. Same as Stdlib.Option.to_seq Renamed from to_std_seq since 3.0.

since
3.0
val to_iter : 'a t -> 'a iter

to_iter o returns an internal iterator, like in the library Iter.

since
2.8
val pp : 'a printer -> 'a t printer

pp ppf o pretty-prints option o using ppf.

\ No newline at end of file diff --git a/dev/containers/CCUtf8_string/index.html b/dev/containers/CCUtf8_string/index.html index f2ded12e..ca694a65 100644 --- a/dev/containers/CCUtf8_string/index.html +++ b/dev/containers/CCUtf8_string/index.html @@ -1,2 +1,2 @@ -CCUtf8_string (containers.CCUtf8_string)

Module CCUtf8_string

Unicode String, in UTF8

type uchar = Stdlib.Uchar.t
type 'a gen = unit -> 'a option
type 'a iter = ('a -> unit) -> unit

Fast internal iterator.

since
2.8
type t = private string

A UTF8 string

val equal : t -> t -> bool
val hash : t -> int
val compare : t -> t -> int
val pp : Stdlib.Format.formatter -> t -> unit
val to_string : t -> string

Identity.

exception Malformed of string * int

Malformed string at given offset

val to_gen : ?⁠idx:int -> t -> uchar gen

Generator of unicode codepoints.

parameter idx

offset where to start the decoding.

val to_iter : ?⁠idx:int -> t -> uchar iter

Iterator of unicode codepoints.

parameter idx

offset where to start the decoding.

since
2.8
val to_seq : ?⁠idx:int -> t -> uchar Stdlib.Seq.t

Iter of unicode codepoints. Renamed from to_std_seq since 3.0.

parameter idx

offset where to start the decoding.

since
3.0
val to_list : ?⁠idx:int -> t -> uchar list

List of unicode codepoints.

parameter idx

offset where to start the decoding.

val fold : ?⁠idx:int -> ('a -> uchar -> 'a) -> 'a -> t -> 'a
val iter : ?⁠idx:int -> (uchar -> unit) -> t -> unit
val n_chars : t -> int

Number of characters.

val n_bytes : t -> int

Number of bytes.

val map : (uchar -> uchar) -> t -> t
val filter_map : (uchar -> uchar option) -> t -> t
val flat_map : (uchar -> t) -> t -> t
val empty : t

Empty string.

since
NEXT_RELEASE
val append : t -> t -> t

Append two string together.

val concat : t -> t list -> t

concat sep l concatenates each string in l, inserting sep in between each string. Similar to String.concat.

val of_uchar : uchar -> t

of_char c is a string with only one unicode char in it.

since
NEXT_RELEASE
val make : int -> uchar -> t

make n c makes a new string with n copies of c in it.

since
NEXT_RELEASE
val of_seq : uchar Stdlib.Seq.t -> t

Build a string from unicode codepoints Renamed from of_std_seq since 3.0.

since
3.0
val of_iter : uchar iter -> t

Build a string from unicode codepoints

since
2.8
val uchar_to_bytes : uchar -> char iter

Translate the unicode codepoint to a list of utf-8 bytes. This can be used, for example, in combination with Buffer.add_char on a pre-allocated buffer to add the bytes one by one (despite its name, Buffer.add_char takes individual bytes, not unicode codepoints).

since
3.2
val of_gen : uchar gen -> t
val of_list : uchar list -> t
val of_string_exn : string -> t

Validate string by checking it is valid UTF8.

raises Invalid_argument

if the string is not valid UTF8.

val of_string : string -> t option

Safe version of of_string_exn.

val is_valid : string -> bool

Valid UTF8?

val unsafe_of_string : string -> t

Conversion from a string without validating. CAUTION this is unsafe and can break all the other functions in this module. Use only if you're sure the string is valid UTF8. Upon iteration, if an invalid substring is met, Malformed will be raised.

\ No newline at end of file +CCUtf8_string (containers.CCUtf8_string)

Module CCUtf8_string

Unicode String, in UTF8

type uchar = Stdlib.Uchar.t
type 'a gen = unit -> 'a option
type 'a iter = ('a -> unit) -> unit

Fast internal iterator.

since
2.8
type t = private string

A UTF8 string

val equal : t -> t -> bool
val hash : t -> int
val compare : t -> t -> int
val pp : Stdlib.Format.formatter -> t -> unit
val to_string : t -> string

Identity.

exception Malformed of string * int

Malformed string at given offset

val to_gen : ?⁠idx:int -> t -> uchar gen

Generator of unicode codepoints.

parameter idx

offset where to start the decoding.

val to_iter : ?⁠idx:int -> t -> uchar iter

Iterator of unicode codepoints.

parameter idx

offset where to start the decoding.

since
2.8
val to_seq : ?⁠idx:int -> t -> uchar Stdlib.Seq.t

Iter of unicode codepoints. Renamed from to_std_seq since 3.0.

parameter idx

offset where to start the decoding.

since
3.0
val to_list : ?⁠idx:int -> t -> uchar list

List of unicode codepoints.

parameter idx

offset where to start the decoding.

val fold : ?⁠idx:int -> ('a -> uchar -> 'a) -> 'a -> t -> 'a
val iter : ?⁠idx:int -> (uchar -> unit) -> t -> unit
val n_chars : t -> int

Number of characters.

val n_bytes : t -> int

Number of bytes.

val map : (uchar -> uchar) -> t -> t
val filter_map : (uchar -> uchar option) -> t -> t
val flat_map : (uchar -> t) -> t -> t
val empty : t

Empty string.

since
3.5
val append : t -> t -> t

Append two string together.

val concat : t -> t list -> t

concat sep l concatenates each string in l, inserting sep in between each string. Similar to String.concat.

val of_uchar : uchar -> t

of_char c is a string with only one unicode char in it.

since
3.5
val make : int -> uchar -> t

make n c makes a new string with n copies of c in it.

since
3.5
val of_seq : uchar Stdlib.Seq.t -> t

Build a string from unicode codepoints Renamed from of_std_seq since 3.0.

since
3.0
val of_iter : uchar iter -> t

Build a string from unicode codepoints

since
2.8
val uchar_to_bytes : uchar -> char iter

Translate the unicode codepoint to a list of utf-8 bytes. This can be used, for example, in combination with Buffer.add_char on a pre-allocated buffer to add the bytes one by one (despite its name, Buffer.add_char takes individual bytes, not unicode codepoints).

since
3.2
val of_gen : uchar gen -> t
val of_list : uchar list -> t
val of_string_exn : string -> t

Validate string by checking it is valid UTF8.

raises Invalid_argument

if the string is not valid UTF8.

val of_string : string -> t option

Safe version of of_string_exn.

val is_valid : string -> bool

Valid UTF8?

val unsafe_of_string : string -> t

Conversion from a string without validating. CAUTION this is unsafe and can break all the other functions in this module. Use only if you're sure the string is valid UTF8. Upon iteration, if an invalid substring is met, Malformed will be raised.

\ No newline at end of file diff --git a/dev/index.html b/dev/index.html index 29436259..e749c4fd 100644 --- a/dev/index.html +++ b/dev/index.html @@ -11,9 +11,9 @@

OCaml package documentation

    -
  1. containers 3.4
  2. -
  3. containers-data 3.4
  4. -
  5. containers-thread 3.4
  6. +
  7. containers 3.5
  8. +
  9. containers-data 3.5
  10. +
  11. containers-thread 3.5