Module CCOpt.Infix
val (<*>) : ('a -> 'b) t -> 'a t -> 'b tf <*> oreturnsSome (f x)ifoisSome xandNoneifoisNone.
Let operators on OCaml >= 4.08.0, nothing otherwise
- since
- 2.8
diff --git a/dev/containers/CCList/index.html b/dev/containers/CCList/index.html index f3f6f1a0..50ea0338 100644 --- a/dev/containers/CCList/index.html +++ b/dev/containers/CCList/index.html @@ -3,7 +3,7 @@ [[1;3;4];[1;3;5];[1;3;6];[2;3;4];[2;3;5];[2;3;6]];; # cartesian_product [[1;2];[];[4;5;6]] = [];; # cartesian_product [[1;2];[3];[4];[5];[6]] |> sort = -[[1;3;4;5;6];[2;3;4;5;6]];;
invariant: cartesian_product l = map_product id l.
val map_product_l : ('a -> 'b list) -> 'a list -> 'b list listmap_product_l f l maps each element of l to a list of objects of type 'b using f. We obtain [l1; l2; …; ln] where length l=n and li : 'b list. Then, it returns all the ways of picking exactly one element per li.
val diagonal : 'a t -> ('a * 'a) tdiagonal l returns all pairs of distinct positions of the list l, that is the list of List.nth i l, List.nth j l if i < j.
val partition_map_either : ('a -> ('b, 'c) CCEither.t) -> 'a list -> 'b list * 'c listpartition_map_either f l maps f on l and gather results in lists:
f x = Left y, adds y to the first list.f x = Right z, adds z to the second list.val partition_filter_map : ('a -> [< `Left of 'b | `Right of 'c | `Drop ]) -> 'a list -> 'b list * 'c listpartition_filter_map f l maps f on l and gather results in lists:
f x = `Left y, adds y to the first list.f x = `Right z, adds z to the second list.f x = `Drop, ignores x.val partition_map : ('a -> [< `Left of 'b | `Right of 'c | `Drop ]) -> 'a list -> 'b list * 'c listuse partition_filter_map instead
val group_by : ?hash:('a -> int) -> ?eq:('a -> 'a -> bool) -> 'a t -> 'a list tgroup_by ?hash ?eq l groups equal elements, regardless of their order of appearance. precondition: for any x and y, if eq x y then hash x=hash y must hold.
val join : join_row:('a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c tjoin ~join_row a b combines every element of a with every element of b using join_row. If join_row returns None, then the two elements do not combine. Assume that b allows for multiple iterations.
val join_by : ?eq:('key -> 'key -> bool) -> ?hash:('key -> int) -> ('a -> 'key) -> ('b -> 'key) -> merge:('key -> 'a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c tjoin_by ?eq ?hash key1 key2 ~merge la lb is a binary operation that takes two sequences a and b, projects their elements resp. with key1 and key2, and combine values (x,y) from (a,b) with the same key using merge. If merge returns None, the combination of values is discarded. precondition: for any x and y, if eq x y then hash x=hash y must hold.
val join_all_by : ?eq:('key -> 'key -> bool) -> ?hash:('key -> int) -> ('a -> 'key) -> ('b -> 'key) -> merge:('key -> 'a list -> 'b list -> 'c option) -> 'a t -> 'b t -> 'c tjoin_all_by ?eq ?hash key1 key2 ~merge la lb is a binary operation that takes two sequences a and b, projects their elements resp. with key1 and key2, and, for each key k occurring in at least one of them:
l1 of elements of a that map to kl2 of elements of b that map to kmerge k l1 l2. If merge returns None, the combination of values is discarded, otherwise it returns Some c and c is inserted in the result.val group_join_by : ?eq:('a -> 'a -> bool) -> ?hash:('a -> int) -> ('b -> 'a) -> 'a t -> 'b t -> ('a * 'b list) tgroup_join_by ?eq ?hash key la lb associates to every element x of the first sequence, all the elements y of the second sequence such that eq x (key y). Elements of the first sequences without corresponding values in the second one are mapped to [] precondition: for any x and y, if eq x y then hash x=hash y must hold.
val sublists_of_len : ?last:('a list -> 'a list option) -> ?offset:int -> int -> 'a list -> 'a list listsublists_of_len ?last ?offset n l returns sub-lists of l that have length n. By default, these sub-lists are non overlapping: sublists_of_len 2 [1;2;3;4;5;6] returns [1;2]; [3;4]; [5;6].
Examples:
sublists_of_len 2 [1;2;3;4;5;6] = [[1;2]; [3;4]; [5;6]].sublists_of_len 2 ~offset:3 [1;2;3;4;5;6] = [1;2];[4;5].sublists_of_len 3 ~last:CCOpt.return [1;2;3;4] = [1;2;3];[4].sublists_of_len 2 [1;2;3;4;5] = [[1;2]; [3;4]].the number of elements skipped between two consecutive sub-lists. By default it is n. If offset < n, the sub-lists will overlap; if offset > n, some elements will not appear at all.
if provided and the last group of elements g is such that length g < n, last g is called. If last g = Some g', g' is appended; otherwise g is dropped. If last = CCOpt.return, it will simply keep the last group. By default, last = fun _ -> None, i.e. the last group is dropped if shorter than n.
if offset <= 0 or n <= 0. See CCList.sublists_of_len for more details.
val chunks : int -> 'a list -> 'a list listchunks n l returns consecutives chunks of size at most n from l. Each item of l will occur in exactly one chunk. Only the last chunk might be of length smaller than n. Invariant: (chunks n l |> List.flatten) = l.
val intersperse : 'a -> 'a list -> 'a listintersperse x l inserts the element x between adjacent elements of the list l.
val interleave : 'a list -> 'a list -> 'a listinterleave [x1…xn] [y1…ym] is [x1;y1;x2;y2;…] and finishes with the suffix of the longest list.
val pure : 'a -> 'a tpure x is return x.
val mguard : bool -> unit tmguard c is pure () if c is true, [] otherwise. This is useful to define a list by comprehension, e.g.:
# let square_even xs =
+[[1;3;4;5;6];[2;3;4;5;6]];;invariant: cartesian_product l = map_product id l.
val map_product_l : ('a -> 'b list) -> 'a list -> 'b list listmap_product_l f l maps each element of l to a list of objects of type 'b using f. We obtain [l1; l2; …; ln] where length l=n and li : 'b list. Then, it returns all the ways of picking exactly one element per li.
val diagonal : 'a t -> ('a * 'a) tdiagonal l returns all pairs of distinct positions of the list l, that is the list of List.nth i l, List.nth j l if i < j.
val partition_map_either : ('a -> ('b, 'c) CCEither.t) -> 'a list -> 'b list * 'c listpartition_map_either f l maps f on l and gather results in lists:
f x = Left y, adds y to the first list.f x = Right z, adds z to the second list.val partition_filter_map : ('a -> [< `Left of 'b | `Right of 'c | `Drop ]) -> 'a list -> 'b list * 'c listpartition_filter_map f l maps f on l and gather results in lists:
f x = `Left y, adds y to the first list.f x = `Right z, adds z to the second list.f x = `Drop, ignores x.val partition_map : ('a -> [< `Left of 'b | `Right of 'c | `Drop ]) -> 'a list -> 'b list * 'c listuse partition_filter_map instead
val group_by : ?hash:('a -> int) -> ?eq:('a -> 'a -> bool) -> 'a t -> 'a list tgroup_by ?hash ?eq l groups equal elements, regardless of their order of appearance. precondition: for any x and y, if eq x y then hash x=hash y must hold.
val join : join_row:('a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c tjoin ~join_row a b combines every element of a with every element of b using join_row. If join_row returns None, then the two elements do not combine. Assume that b allows for multiple iterations.
val join_by : ?eq:('key -> 'key -> bool) -> ?hash:('key -> int) -> ('a -> 'key) -> ('b -> 'key) -> merge:('key -> 'a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c tjoin_by ?eq ?hash key1 key2 ~merge la lb is a binary operation that takes two sequences a and b, projects their elements resp. with key1 and key2, and combine values (x,y) from (a,b) with the same key using merge. If merge returns None, the combination of values is discarded. precondition: for any x and y, if eq x y then hash x=hash y must hold.
val join_all_by : ?eq:('key -> 'key -> bool) -> ?hash:('key -> int) -> ('a -> 'key) -> ('b -> 'key) -> merge:('key -> 'a list -> 'b list -> 'c option) -> 'a t -> 'b t -> 'c tjoin_all_by ?eq ?hash key1 key2 ~merge la lb is a binary operation that takes two sequences a and b, projects their elements resp. with key1 and key2, and, for each key k occurring in at least one of them:
l1 of elements of a that map to kl2 of elements of b that map to kmerge k l1 l2. If merge returns None, the combination of values is discarded, otherwise it returns Some c and c is inserted in the result.val group_join_by : ?eq:('a -> 'a -> bool) -> ?hash:('a -> int) -> ('b -> 'a) -> 'a t -> 'b t -> ('a * 'b list) tgroup_join_by ?eq ?hash key la lb associates to every element x of the first sequence, all the elements y of the second sequence such that eq x (key y). Elements of the first sequences without corresponding values in the second one are mapped to [] precondition: for any x and y, if eq x y then hash x=hash y must hold.
val sublists_of_len : ?last:('a list -> 'a list option) -> ?offset:int -> int -> 'a list -> 'a list listsublists_of_len ?last ?offset n l returns sub-lists of l that have length n. By default, these sub-lists are non overlapping: sublists_of_len 2 [1;2;3;4;5;6] returns [1;2]; [3;4]; [5;6].
Examples:
sublists_of_len 2 [1;2;3;4;5;6] = [[1;2]; [3;4]; [5;6]].sublists_of_len 2 ~offset:3 [1;2;3;4;5;6] = [1;2];[4;5].sublists_of_len 3 ~last:CCOption.return [1;2;3;4] = [1;2;3];[4].sublists_of_len 2 [1;2;3;4;5] = [[1;2]; [3;4]].the number of elements skipped between two consecutive sub-lists. By default it is n. If offset < n, the sub-lists will overlap; if offset > n, some elements will not appear at all.
if provided and the last group of elements g is such that length g < n, last g is called. If last g = Some g', g' is appended; otherwise g is dropped. If last = CCOption.return, it will simply keep the last group. By default, last = fun _ -> None, i.e. the last group is dropped if shorter than n.
if offset <= 0 or n <= 0. See CCList.sublists_of_len for more details.
val chunks : int -> 'a list -> 'a list listchunks n l returns consecutives chunks of size at most n from l. Each item of l will occur in exactly one chunk. Only the last chunk might be of length smaller than n. Invariant: (chunks n l |> List.flatten) = l.
val intersperse : 'a -> 'a list -> 'a listintersperse x l inserts the element x between adjacent elements of the list l.
val interleave : 'a list -> 'a list -> 'a listinterleave [x1…xn] [y1…ym] is [x1;y1;x2;y2;…] and finishes with the suffix of the longest list.
val pure : 'a -> 'a tpure x is return x.
val mguard : bool -> unit tmguard c is pure () if c is true, [] otherwise. This is useful to define a list by comprehension, e.g.:
# let square_even xs =
let* x = xs in
let* () = mguard (x mod 2 = 0) in
return @@ x * x;;
diff --git a/dev/containers/CCListLabels/index.html b/dev/containers/CCListLabels/index.html
index 155fbca8..e7727757 100644
--- a/dev/containers/CCListLabels/index.html
+++ b/dev/containers/CCListLabels/index.html
@@ -3,7 +3,7 @@
[[1;3;4];[1;3;5];[1;3;6];[2;3;4];[2;3;5];[2;3;6]];;
# cartesian_product [[1;2];[];[4;5;6]] = [];;
# cartesian_product [[1;2];[3];[4];[5];[6]] |> sort =
-[[1;3;4;5;6];[2;3;4;5;6]];;invariant: cartesian_product l = map_product id l.
val map_product_l : f:('a -> 'b list) -> 'a list -> 'b list listmap_product_l ~f l maps each element of l to a list of objects of type 'b using f. We obtain [l1; l2; …; ln] where length l=n and li : 'b list. Then, it returns all the ways of picking exactly one element per li.
val diagonal : 'a t -> ('a * 'a) tdiagonal l returns all pairs of distinct positions of the list l, that is the list of List.nth i l, List.nth j l if i < j.
val partition_map_either : f:('a -> ('b, 'c) CCEither.t) -> 'a list -> 'b list * 'c listpartition_map_either ~f l maps f on l and gather results in lists:
f x = Left y, adds y to the first list.f x = Right z, adds z to the second list.val partition_filter_map : f:('a -> [< `Left of 'b | `Right of 'c | `Drop ]) -> 'a list -> 'b list * 'c listpartition_filter_map ~f l maps f on l and gather results in lists:
f x = `Left y, adds y to the first list.f x = `Right z, adds z to the second list.f x = `Drop, ignores x.val partition_map : f:('a -> [< `Left of 'b | `Right of 'c | `Drop ]) -> 'a list -> 'b list * 'c listuse partition_filter_map instead
val group_by : ?hash:('a -> int) -> ?eq:('a -> 'a -> bool) -> 'a t -> 'a list tgroup_by ?hash ?eq l groups equal elements, regardless of their order of appearance. precondition: for any x and y, if eq x y then hash x = hash y must hold.
val join : join_row:('a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c tjoin ~join_row a b combines every element of a with every element of b using join_row. If join_row returns None, then the two elements do not combine. Assume that b allows for multiple iterations.
val join_by : ?eq:('key -> 'key -> bool) -> ?hash:('key -> int) -> ('a -> 'key) -> ('b -> 'key) -> merge:('key -> 'a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c tjoin_by ?eq ?hash key1 key2 ~merge la lb is a binary operation that takes two sequences a and b, projects their elements resp. with key1 and key2, and combine values (x,y) from (a,b) with the same key using merge. If merge returns None, the combination of values is discarded. precondition: for any x and y, if eq x y then hash x = hash y must hold.
val join_all_by : ?eq:('key -> 'key -> bool) -> ?hash:('key -> int) -> ('a -> 'key) -> ('b -> 'key) -> merge:('key -> 'a list -> 'b list -> 'c option) -> 'a t -> 'b t -> 'c tjoin_all_by ?eq ?hash key1 key2 ~merge la lb is a binary operation that takes two sequences a and b, projects their elements resp. with key1 and key2, and, for each key k occurring in at least one of them:
l1 of elements of a that map to kl2 of elements of b that map to kmerge k l1 l2. If merge returns None, the combination of values is discarded, otherwise it returns Some c and c is inserted in the result.val group_join_by : ?eq:('a -> 'a -> bool) -> ?hash:('a -> int) -> ('b -> 'a) -> 'a t -> 'b t -> ('a * 'b list) tgroup_join_by ?eq ?hash key la lb associates to every element x of the first sequence, all the elements y of the second sequence such that eq x (key y). Elements of the first sequences without corresponding values in the second one are mapped to [] precondition: for any x and y, if eq x y then hash x = hash y must hold.
val sublists_of_len : ?last:('a list -> 'a list option) -> ?offset:int -> len:int -> 'a list -> 'a list listsublists_of_len ?last ?offset n l returns sub-lists of l that have length n. By default, these sub-lists are non overlapping: sublists_of_len 2 [1;2;3;4;5;6] returns [1;2]; [3;4]; [5;6].
Examples:
sublists_of_len 2 [1;2;3;4;5;6] = [[1;2]; [3;4]; [5;6]].sublists_of_len 2 ~offset:3 [1;2;3;4;5;6] = [1;2];[4;5].sublists_of_len 3 ~last:CCOpt.return [1;2;3;4] = [1;2;3];[4].sublists_of_len 2 [1;2;3;4;5] = [[1;2]; [3;4]].the number of elements skipped between two consecutive sub-lists. By default it is n. If offset < n, the sub-lists will overlap; if offset > n, some elements will not appear at all.
if provided and the last group of elements g is such that length g < n, last g is called. If last g = Some g', g' is appended; otherwise g is dropped. If last = CCOpt.return, it will simply keep the last group. By default, last = fun _ -> None, i.e. the last group is dropped if shorter than n.
if offset <= 0 or n <= 0. See CCList.sublists_of_len for more details.
val chunks : int -> 'a list -> 'a list listchunks n l returns consecutives chunks of size at most n from l. Each item of l will occur in exactly one chunk. Only the last chunk might be of length smaller than n. Invariant: (chunks n l |> List.flatten) = l.
val intersperse : x:'a -> 'a list -> 'a listintersperse ~x l inserts the element x between adjacent elements of the list l.
val interleave : 'a list -> 'a list -> 'a listinterleave [x1…xn] [y1…ym] is [x1,y1,x2,y2,…] and finishes with the suffix of the longest list.
val pure : 'a -> 'a tpure x is return x.
val mguard : bool -> unit tmguard c is pure () if c is true, [] otherwise. This is useful to define a list by comprehension, e.g.:
# let square_even xs =
+[[1;3;4;5;6];[2;3;4;5;6]];;invariant: cartesian_product l = map_product id l.
val map_product_l : f:('a -> 'b list) -> 'a list -> 'b list listmap_product_l ~f l maps each element of l to a list of objects of type 'b using f. We obtain [l1; l2; …; ln] where length l=n and li : 'b list. Then, it returns all the ways of picking exactly one element per li.
val diagonal : 'a t -> ('a * 'a) tdiagonal l returns all pairs of distinct positions of the list l, that is the list of List.nth i l, List.nth j l if i < j.
val partition_map_either : f:('a -> ('b, 'c) CCEither.t) -> 'a list -> 'b list * 'c listpartition_map_either ~f l maps f on l and gather results in lists:
f x = Left y, adds y to the first list.f x = Right z, adds z to the second list.val partition_filter_map : f:('a -> [< `Left of 'b | `Right of 'c | `Drop ]) -> 'a list -> 'b list * 'c listpartition_filter_map ~f l maps f on l and gather results in lists:
f x = `Left y, adds y to the first list.f x = `Right z, adds z to the second list.f x = `Drop, ignores x.val partition_map : f:('a -> [< `Left of 'b | `Right of 'c | `Drop ]) -> 'a list -> 'b list * 'c listuse partition_filter_map instead
val group_by : ?hash:('a -> int) -> ?eq:('a -> 'a -> bool) -> 'a t -> 'a list tgroup_by ?hash ?eq l groups equal elements, regardless of their order of appearance. precondition: for any x and y, if eq x y then hash x = hash y must hold.
val join : join_row:('a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c tjoin ~join_row a b combines every element of a with every element of b using join_row. If join_row returns None, then the two elements do not combine. Assume that b allows for multiple iterations.
val join_by : ?eq:('key -> 'key -> bool) -> ?hash:('key -> int) -> ('a -> 'key) -> ('b -> 'key) -> merge:('key -> 'a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c tjoin_by ?eq ?hash key1 key2 ~merge la lb is a binary operation that takes two sequences a and b, projects their elements resp. with key1 and key2, and combine values (x,y) from (a,b) with the same key using merge. If merge returns None, the combination of values is discarded. precondition: for any x and y, if eq x y then hash x = hash y must hold.
val join_all_by : ?eq:('key -> 'key -> bool) -> ?hash:('key -> int) -> ('a -> 'key) -> ('b -> 'key) -> merge:('key -> 'a list -> 'b list -> 'c option) -> 'a t -> 'b t -> 'c tjoin_all_by ?eq ?hash key1 key2 ~merge la lb is a binary operation that takes two sequences a and b, projects their elements resp. with key1 and key2, and, for each key k occurring in at least one of them:
l1 of elements of a that map to kl2 of elements of b that map to kmerge k l1 l2. If merge returns None, the combination of values is discarded, otherwise it returns Some c and c is inserted in the result.val group_join_by : ?eq:('a -> 'a -> bool) -> ?hash:('a -> int) -> ('b -> 'a) -> 'a t -> 'b t -> ('a * 'b list) tgroup_join_by ?eq ?hash key la lb associates to every element x of the first sequence, all the elements y of the second sequence such that eq x (key y). Elements of the first sequences without corresponding values in the second one are mapped to [] precondition: for any x and y, if eq x y then hash x = hash y must hold.
val sublists_of_len : ?last:('a list -> 'a list option) -> ?offset:int -> len:int -> 'a list -> 'a list listsublists_of_len ?last ?offset n l returns sub-lists of l that have length n. By default, these sub-lists are non overlapping: sublists_of_len 2 [1;2;3;4;5;6] returns [1;2]; [3;4]; [5;6].
Examples:
sublists_of_len 2 [1;2;3;4;5;6] = [[1;2]; [3;4]; [5;6]].sublists_of_len 2 ~offset:3 [1;2;3;4;5;6] = [1;2];[4;5].sublists_of_len 3 ~last:CCOption.return [1;2;3;4] = [1;2;3];[4].sublists_of_len 2 [1;2;3;4;5] = [[1;2]; [3;4]].the number of elements skipped between two consecutive sub-lists. By default it is n. If offset < n, the sub-lists will overlap; if offset > n, some elements will not appear at all.
if provided and the last group of elements g is such that length g < n, last g is called. If last g = Some g', g' is appended; otherwise g is dropped. If last = CCOption.return, it will simply keep the last group. By default, last = fun _ -> None, i.e. the last group is dropped if shorter than n.
if offset <= 0 or n <= 0. See CCList.sublists_of_len for more details.
val chunks : int -> 'a list -> 'a list listchunks n l returns consecutives chunks of size at most n from l. Each item of l will occur in exactly one chunk. Only the last chunk might be of length smaller than n. Invariant: (chunks n l |> List.flatten) = l.
val intersperse : x:'a -> 'a list -> 'a listintersperse ~x l inserts the element x between adjacent elements of the list l.
val interleave : 'a list -> 'a list -> 'a listinterleave [x1…xn] [y1…ym] is [x1,y1,x2,y2,…] and finishes with the suffix of the longest list.
val pure : 'a -> 'a tpure x is return x.
val mguard : bool -> unit tmguard c is pure () if c is true, [] otherwise. This is useful to define a list by comprehension, e.g.:
# let square_even xs =
let* x = xs in
let* () = mguard (x mod 2 = 0) in
return @@ x * x;;
diff --git a/dev/containers/CCOpt/Infix/index.html b/dev/containers/CCOpt/Infix/index.html
deleted file mode 100644
index 7df5e042..00000000
--- a/dev/containers/CCOpt/Infix/index.html
+++ /dev/null
@@ -1,2 +0,0 @@
-
-Infix (containers.CCOpt.Infix) Module CCOpt.Infix
val (<*>) : ('a -> 'b) t -> 'a t -> 'b tf <*> o returns Some (f x) if o is Some x and None if o is None.
Let operators on OCaml >= 4.08.0, nothing otherwise
- since
- 2.8
\ No newline at end of file
diff --git a/dev/containers/CCOpt/index.html b/dev/containers/CCOpt/index.html
index 92371ffd..e11eacb4 100644
--- a/dev/containers/CCOpt/index.html
+++ b/dev/containers/CCOpt/index.html
@@ -1,2 +1,2 @@
-CCOpt (containers.CCOpt) Module CCOpt
Options
val map_or : default:'b -> ('a -> 'b) -> 'a t -> 'bmap_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 -> 'bmap_lazy default_fn f o if f o if o = Some x, default_fn () otherwise.
- since
- 1.2
val is_some : _ t -> boolis_some (Some x) returns true otherwise it returns false.
val is_none : _ t -> boolis_none None returns true otherwise it returns false.
- since
- 0.11
val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> intcompare 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 -> boolequal p o1 o2 tests for equality between option types o1 and o2, using a custom equality predicate p.
val return : 'a -> 'a treturn x is a monadic return, that is return x = Some x.
val none : 'a tAlias to None.
- since
- 3.5
val flat_map : ('a -> 'b t) -> 'a t -> 'b tflat_map f o is equivalent to map followed by flatten. Flip version of >>=.
val bind : 'a t -> ('a -> 'b t) -> 'b tbind o f is f v if o is Some v, None otherwise. Monadic bind.
- since
- 3.0
val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c tmap2 f o1 o2 maps 'a option and 'b option to a 'c option using f.
val iter : ('a -> unit) -> 'a t -> unititer f o applies f to o. Iterate on 0 or 1 element.
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'afold 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 tfilter 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 exists : ('a -> bool) -> 'a t -> boolexists 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 -> boolfor_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 -> 'aget_or ~default o extracts the value from o, or returns default if o is None.
- since
- 0.18
val value : 'a t -> default:'a -> 'avalue o ~default is similar to the Stdlib's Option.value and to get_or.
- since
- 2.8
val get_exn : 'a t -> 'aget_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 -> 'aget_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 -> 'aget_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 tsequence_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 optionwrap ?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 optionwrap2 ?handler f x y is similar to wrap but for binary functions.
Applicative
Alternatives
val or_lazy : else_:(unit -> 'a t) -> 'a t -> 'a tor_lazy ~else_ o is o if o is Some _, else_ () if o is None.
- since
- 1.2
val return_if : bool -> 'a -> 'a treturn_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 ... endLet operators on OCaml >= 4.08.0, nothing otherwise
- since
- 2.8
Conversion and IO
val to_list : 'a t -> 'a listto_list o returns [x] if o is Some x or the empty list [] if o is None.
val of_list : 'a list -> 'a tof_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.resultto_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.resultto_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 tof_result result returns an option from a result.
- since
- 1.2
type 'a iter = ('a -> unit) -> unittype 'a gen = unit -> 'a optiontype 'a printer = Stdlib.Format.formatter -> 'a -> unittype 'a random_gen = Stdlib.Random.State.t -> 'a
val random : 'a random_gen -> 'a t random_genval choice_iter : 'a t iter -> 'a tchoice_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 tchoice_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 gento_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.tto_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
\ No newline at end of file
+CCOpt (containers.CCOpt) Module CCOpt
include module type of CCOption
val map_or : default:'b -> ('a -> 'b) -> 'a t -> 'bmap_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 -> 'bmap_lazy default_fn f o if f o if o = Some x, default_fn () otherwise.
- since
- 1.2
val is_some : _ t -> boolis_some (Some x) returns true otherwise it returns false.
val is_none : _ t -> boolis_none None returns true otherwise it returns false.
- since
- 0.11
val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> intcompare 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 -> boolequal p o1 o2 tests for equality between option types o1 and o2, using a custom equality predicate p.
val return : 'a -> 'a treturn x is a monadic return, that is return x = Some x.
val none : 'a tAlias to None.
- since
- 3.5
val flat_map : ('a -> 'b t) -> 'a t -> 'b tflat_map f o is equivalent to map followed by flatten. Flip version of >>=.
val bind : 'a t -> ('a -> 'b t) -> 'b tbind o f is f v if o is Some v, None otherwise. Monadic bind.
- since
- 3.0
val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c tmap2 f o1 o2 maps 'a option and 'b option to a 'c option using f.
val iter : ('a -> unit) -> 'a t -> unititer f o applies f to o. Iterate on 0 or 1 element.
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'afold 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 tfilter 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 exists : ('a -> bool) -> 'a t -> boolexists 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 -> boolfor_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 -> 'aget_or ~default o extracts the value from o, or returns default if o is None.
- since
- 0.18
val value : 'a t -> default:'a -> 'avalue o ~default is similar to the Stdlib's Option.value and to get_or.
- since
- 2.8
val get_exn : 'a t -> 'aget_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 -> 'aget_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 -> 'aget_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 tsequence_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 optionwrap ?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 optionwrap2 ?handler f x y is similar to wrap but for binary functions.
Applicative
Alternatives
val or_lazy : else_:(unit -> 'a t) -> 'a t -> 'a tor_lazy ~else_ o is o if o is Some _, else_ () if o is None.
- since
- 1.2
val return_if : bool -> 'a -> 'a treturn_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 = CCOption.InfixLet operators on OCaml >= 4.08.0, nothing otherwise
- since
- 2.8
Conversion and IO
val to_list : 'a t -> 'a listto_list o returns [x] if o is Some x or the empty list [] if o is None.
val of_list : 'a list -> 'a tof_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.resultto_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.resultto_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 tof_result result returns an option from a result.
- since
- 1.2
type 'a iter = ('a -> unit) -> unittype 'a gen = unit -> 'a optiontype 'a printer = Stdlib.Format.formatter -> 'a -> unittype 'a random_gen = Stdlib.Random.State.t -> 'a
val random : 'a random_gen -> 'a t random_genval choice_iter : 'a t iter -> 'a tchoice_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 tchoice_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 gento_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.tto_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
\ No newline at end of file
diff --git a/dev/containers/CCOption/.dune-keep b/dev/containers/CCOption/.dune-keep
new file mode 100644
index 00000000..e69de29b
diff --git a/dev/containers/CCOption/Infix/index.html b/dev/containers/CCOption/Infix/index.html
new file mode 100644
index 00000000..a430e287
--- /dev/null
+++ b/dev/containers/CCOption/Infix/index.html
@@ -0,0 +1,2 @@
+
+Infix (containers.CCOption.Infix) Module CCOption.Infix
val (<*>) : ('a -> 'b) t -> 'a t -> 'b tf <*> o returns Some (f x) if o is Some x and None if o is None.
Let operators on OCaml >= 4.08.0, nothing otherwise
- since
- 2.8
\ No newline at end of file
diff --git a/dev/containers/CCOption/index.html b/dev/containers/CCOption/index.html
new file mode 100644
index 00000000..c152c406
--- /dev/null
+++ b/dev/containers/CCOption/index.html
@@ -0,0 +1,2 @@
+
+CCOption (containers.CCOption) Module CCOption
Options
This module replaces `CCOpt`.
- since
- NEXT_RELEASE
val map_or : default:'b -> ('a -> 'b) -> 'a t -> 'bmap_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 -> 'bmap_lazy default_fn f o if f o if o = Some x, default_fn () otherwise.
- since
- 1.2
val is_some : _ t -> boolis_some (Some x) returns true otherwise it returns false.
val is_none : _ t -> boolis_none None returns true otherwise it returns false.
- since
- 0.11
val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> intcompare 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 -> boolequal p o1 o2 tests for equality between option types o1 and o2, using a custom equality predicate p.
val return : 'a -> 'a treturn x is a monadic return, that is return x = Some x.
val none : 'a tAlias to None.
- since
- 3.5
val flat_map : ('a -> 'b t) -> 'a t -> 'b tflat_map f o is equivalent to map followed by flatten. Flip version of >>=.
val bind : 'a t -> ('a -> 'b t) -> 'b tbind o f is f v if o is Some v, None otherwise. Monadic bind.
- since
- 3.0
val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c tmap2 f o1 o2 maps 'a option and 'b option to a 'c option using f.
val iter : ('a -> unit) -> 'a t -> unititer f o applies f to o. Iterate on 0 or 1 element.
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'afold 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 tfilter 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 exists : ('a -> bool) -> 'a t -> boolexists 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 -> boolfor_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 -> 'aget_or ~default o extracts the value from o, or returns default if o is None.
- since
- 0.18
val value : 'a t -> default:'a -> 'avalue o ~default is similar to the Stdlib's Option.value and to get_or.
- since
- 2.8
val get_exn : 'a t -> 'aget_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 -> 'aget_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 -> 'aget_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 tsequence_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 optionwrap ?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 optionwrap2 ?handler f x y is similar to wrap but for binary functions.
Applicative
Alternatives
val or_lazy : else_:(unit -> 'a t) -> 'a t -> 'a tor_lazy ~else_ o is o if o is Some _, else_ () if o is None.
- since
- 1.2
val return_if : bool -> 'a -> 'a treturn_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 ... endLet operators on OCaml >= 4.08.0, nothing otherwise
- since
- 2.8
Conversion and IO
val to_list : 'a t -> 'a listto_list o returns [x] if o is Some x or the empty list [] if o is None.
val of_list : 'a list -> 'a tof_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.resultto_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.resultto_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 tof_result result returns an option from a result.
- since
- 1.2
type 'a iter = ('a -> unit) -> unittype 'a gen = unit -> 'a optiontype 'a printer = Stdlib.Format.formatter -> 'a -> unittype 'a random_gen = Stdlib.Random.State.t -> 'a
val random : 'a random_gen -> 'a t random_genval choice_iter : 'a t iter -> 'a tchoice_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 tchoice_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 gento_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.tto_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
\ No newline at end of file
diff --git a/dev/containers/CCResult/index.html b/dev/containers/CCResult/index.html
index c532a149..937e237a 100644
--- a/dev/containers/CCResult/index.html
+++ b/dev/containers/CCResult/index.html
@@ -1,2 +1,2 @@
-CCResult (containers.CCResult) Module CCResult
Error Monad
Uses the new "result" type from OCaml 4.03.
- since
- 0.16
type 'a equal = 'a -> 'a -> booltype 'a ord = 'a -> 'a -> inttype 'a printer = Stdlib.Format.formatter -> 'a -> unit
Basics
type nonrec (+'good, +'bad) result = ('good, 'bad) Stdlib.result = | Ok of 'good| Error of 'bad
type (+'good, +'bad) t = ('good, 'bad) result = | Ok of 'good| Error of 'bad
val return : 'a -> ('a, 'err) tSuccessfully return a value.
val fail : 'err -> ('a, 'err) tFail with an error.
val of_exn : exn -> ('a, string) tof_exn e uses Printexc to print the exception as a string.
val of_exn_trace : exn -> ('a, string) tof_exn_trace e is similar to of_exn e, but it adds the stacktrace to the error message.
Remember to call Printexc.record_backtrace true and compile with the debug flag for this to work.
val fail_printf : ('a, Stdlib.Buffer.t, unit, ('b, string) t) Stdlib.format4 -> 'afail_printf format uses format to obtain an error message and then returns Error msg.
val fail_fprintf : ('a, Stdlib.Format.formatter, unit, ('b, string) t) Stdlib.format4 -> 'afail_fprintf format uses format to obtain an error message and then returns Error msg.
val add_ctx : string -> ('a, string) t -> ('a, string) tadd_ctx msg leaves Ok x untouched, but transforms Error s into Error s' where s' contains the additional context given by msg.
- since
- 1.2
val add_ctxf : ('a, Stdlib.Format.formatter, unit, ('b, string) t -> ('b, string) t) Stdlib.format4 -> 'aadd_ctxf format_message is similar to add_ctx but with Format for printing the message (eagerly). Example:
add_ctxf "message(number %d, foo: %B)" 42 true (Error "error)"
- since
- 1.2
val map2 : ('a -> 'b) -> ('err1 -> 'err2) -> ('a, 'err1) t -> ('b, 'err2) tLike map, but also with a function that can transform the error message in case of failure.
val iter : ('a -> unit) -> ('a, _) t -> unitApply the function only in case of Ok.
val iter_err : ('err -> unit) -> (_, 'err) t -> unitApply the function in case of Error.
- since
- 2.4
val get_exn : ('a, _) t -> 'aExtract the value x from Ok x, fails otherwise. You should be careful with this function, and favor other combinators whenever possible.
- raises Get_error
if the value is an error.
val get_or : ('a, _) t -> default:'a -> 'aget_or e ~default returns x if e = Ok x, default otherwise.
val get_lazy : ('e -> 'a) -> ('a, 'e) t -> 'aget_lazy f e returns x if e = Ok x, f msg if e = Error msg. This is similar to CCOpt.get_lazy.
- since
- 3.0
val get_or_failwith : ('a, string) t -> 'aget_or_failwith e returns x if e = Ok x, fails otherwise.
- raises Failure
with msg if e = Error msg.
- since
- 2.4
val get_lazy : ('b -> 'a) -> ('a, 'b) t -> 'aget_lazy default_fn x unwraps x, but if x = Error e it returns default_fr e instead.
- since
- 3.0
val map_or : ('a -> 'b) -> ('a, 'c) t -> default:'b -> 'bmap_or f e ~default returns f x if e = Ok x, default otherwise.
val catch : ('a, 'err) t -> ok:('a -> 'b) -> err:('err -> 'b) -> 'bcatch e ~ok ~err calls either ok or err depending on the value of e.
val flat_map : ('a -> ('b, 'err) t) -> ('a, 'err) t -> ('b, 'err) tval equal : err:'err equal -> 'a equal -> ('a, 'err) t equalval compare : err:'err ord -> 'a ord -> ('a, 'err) t ordval fold : ok:('a -> 'b) -> error:('err -> 'b) -> ('a, 'err) t -> 'bfold ~ok ~error e opens e and, if e = Ok x, returns ok x, otherwise e = Error s and it returns error s.
val fold_ok : ('a -> 'b -> 'a) -> 'a -> ('b, _) t -> 'afold_ok f acc r will compute f acc x if r=Ok x, and return acc otherwise, as if the result were a mere option.
- since
- 1.2
val is_ok : ('a, 'err) t -> boolReturn true if Ok.
- since
- 1.0
val is_error : ('a, 'err) t -> boolReturn true if Error.
- since
- 1.0
Wrappers
val guard : (unit -> 'a) -> ('a, exn) tguard f runs f () and returns its result wrapped in Ok. If f () raises some exception e, then it fails with Error e.
val guard_str_trace : (unit -> 'a) -> ('a, string) tLike guard_str but uses of_exn_trace instead of of_exn so that the stack trace is printed.
Applicative
Infix
module Infix : sig ... endinclude module type of Infix
val (>>=) : ('a, 'err) t -> ('a -> ('b, 'err) t) -> ('b, 'err) tMonadic composition. e >>= f proceeds as f x if e is Ok x or returns e if e is an Error.
val (<*>) : ('a -> 'b, 'err) t -> ('a, 'err) t -> ('b, 'err) ta <*> b evaluates a and b, and, in case of success, returns Ok (a b). Otherwise, it fails, and the error of a is chosen over the error of b if both fail.
Let operators on OCaml >= 4.08.0, nothing otherwise
- since
- 2.8
include CCShimsMkLet_.S2 with type ('a, 'e) t_let2 := ('a, 'e) result
Let operators on OCaml >= 4.08.0, nothing otherwise
- since
- 2.8
include CCShimsMkLet_.S2 with type ('a, 'e) t_let2 := ('a, 'e) result
Collections
val flatten_l : ('a, 'err) t list -> ('a list, 'err) tSame as map_l id: returns Ok [x1;…;xn] if l=[Ok x1; …; Ok xn], or the first error otherwise.
- since
- 2.7
Misc
val choose : ('a, 'err) t list -> ('a, 'err list) tchoose l selects a member of l that is a Ok _ value, or returns Error l otherwise, where l is the list of errors.
val retry : int -> (unit -> ('a, 'err) t) -> ('a, 'err list) tretry n f calls f at most n times, returning the first result of f () that doesn't fail. If f fails n times, retry n f fails with the list of successive errors.
module type MONAD = sig ... end
Conversions
val to_opt : ('a, _) t -> 'a optionConvert a result to an option.
val of_opt : 'a option -> ('a, string) tConvert an option to a result.
val to_seq : ('a, _) t -> 'a Stdlib.Seq.tRenamed from to_std_seq since 3.0.
- since
- 3.0
IO
\ No newline at end of file
+CCResult (containers.CCResult) Module CCResult
Error Monad
Uses the new "result" type from OCaml 4.03.
- since
- 0.16
type 'a equal = 'a -> 'a -> booltype 'a ord = 'a -> 'a -> inttype 'a printer = Stdlib.Format.formatter -> 'a -> unit
Basics
type nonrec (+'good, +'bad) result = ('good, 'bad) Stdlib.result = | Ok of 'good| Error of 'bad
type (+'good, +'bad) t = ('good, 'bad) result = | Ok of 'good| Error of 'bad
val return : 'a -> ('a, 'err) tSuccessfully return a value.
val fail : 'err -> ('a, 'err) tFail with an error.
val of_exn : exn -> ('a, string) tof_exn e uses Printexc to print the exception as a string.
val of_exn_trace : exn -> ('a, string) tof_exn_trace e is similar to of_exn e, but it adds the stacktrace to the error message.
Remember to call Printexc.record_backtrace true and compile with the debug flag for this to work.
val fail_printf : ('a, Stdlib.Buffer.t, unit, ('b, string) t) Stdlib.format4 -> 'afail_printf format uses format to obtain an error message and then returns Error msg.
val fail_fprintf : ('a, Stdlib.Format.formatter, unit, ('b, string) t) Stdlib.format4 -> 'afail_fprintf format uses format to obtain an error message and then returns Error msg.
val add_ctx : string -> ('a, string) t -> ('a, string) tadd_ctx msg leaves Ok x untouched, but transforms Error s into Error s' where s' contains the additional context given by msg.
- since
- 1.2
val add_ctxf : ('a, Stdlib.Format.formatter, unit, ('b, string) t -> ('b, string) t) Stdlib.format4 -> 'aadd_ctxf format_message is similar to add_ctx but with Format for printing the message (eagerly). Example:
add_ctxf "message(number %d, foo: %B)" 42 true (Error "error)"
- since
- 1.2
val map2 : ('a -> 'b) -> ('err1 -> 'err2) -> ('a, 'err1) t -> ('b, 'err2) tLike map, but also with a function that can transform the error message in case of failure.
val iter : ('a -> unit) -> ('a, _) t -> unitApply the function only in case of Ok.
val iter_err : ('err -> unit) -> (_, 'err) t -> unitApply the function in case of Error.
- since
- 2.4
val get_exn : ('a, _) t -> 'aExtract the value x from Ok x, fails otherwise. You should be careful with this function, and favor other combinators whenever possible.
- raises Get_error
if the value is an error.
val get_or : ('a, _) t -> default:'a -> 'aget_or e ~default returns x if e = Ok x, default otherwise.
val get_lazy : ('e -> 'a) -> ('a, 'e) t -> 'aget_lazy f e returns x if e = Ok x, f msg if e = Error msg. This is similar to CCOption.get_lazy.
- since
- 3.0
val get_or_failwith : ('a, string) t -> 'aget_or_failwith e returns x if e = Ok x, fails otherwise.
- raises Failure
with msg if e = Error msg.
- since
- 2.4
val get_lazy : ('b -> 'a) -> ('a, 'b) t -> 'aget_lazy default_fn x unwraps x, but if x = Error e it returns default_fr e instead.
- since
- 3.0
val map_or : ('a -> 'b) -> ('a, 'c) t -> default:'b -> 'bmap_or f e ~default returns f x if e = Ok x, default otherwise.
val catch : ('a, 'err) t -> ok:('a -> 'b) -> err:('err -> 'b) -> 'bcatch e ~ok ~err calls either ok or err depending on the value of e.
val flat_map : ('a -> ('b, 'err) t) -> ('a, 'err) t -> ('b, 'err) tval equal : err:'err equal -> 'a equal -> ('a, 'err) t equalval compare : err:'err ord -> 'a ord -> ('a, 'err) t ordval fold : ok:('a -> 'b) -> error:('err -> 'b) -> ('a, 'err) t -> 'bfold ~ok ~error e opens e and, if e = Ok x, returns ok x, otherwise e = Error s and it returns error s.
val fold_ok : ('a -> 'b -> 'a) -> 'a -> ('b, _) t -> 'afold_ok f acc r will compute f acc x if r=Ok x, and return acc otherwise, as if the result were a mere option.
- since
- 1.2
val is_ok : ('a, 'err) t -> boolReturn true if Ok.
- since
- 1.0
val is_error : ('a, 'err) t -> boolReturn true if Error.
- since
- 1.0
Wrappers
val guard : (unit -> 'a) -> ('a, exn) tguard f runs f () and returns its result wrapped in Ok. If f () raises some exception e, then it fails with Error e.
val guard_str_trace : (unit -> 'a) -> ('a, string) tLike guard_str but uses of_exn_trace instead of of_exn so that the stack trace is printed.
Applicative
Infix
module Infix : sig ... endinclude module type of Infix
val (>>=) : ('a, 'err) t -> ('a -> ('b, 'err) t) -> ('b, 'err) tMonadic composition. e >>= f proceeds as f x if e is Ok x or returns e if e is an Error.
val (<*>) : ('a -> 'b, 'err) t -> ('a, 'err) t -> ('b, 'err) ta <*> b evaluates a and b, and, in case of success, returns Ok (a b). Otherwise, it fails, and the error of a is chosen over the error of b if both fail.
Let operators on OCaml >= 4.08.0, nothing otherwise
- since
- 2.8
include CCShimsMkLet_.S2 with type ('a, 'e) t_let2 := ('a, 'e) result
Let operators on OCaml >= 4.08.0, nothing otherwise
- since
- 2.8
include CCShimsMkLet_.S2 with type ('a, 'e) t_let2 := ('a, 'e) result
Collections
val flatten_l : ('a, 'err) t list -> ('a list, 'err) tSame as map_l id: returns Ok [x1;…;xn] if l=[Ok x1; …; Ok xn], or the first error otherwise.
- since
- 2.7
Misc
val choose : ('a, 'err) t list -> ('a, 'err list) tchoose l selects a member of l that is a Ok _ value, or returns Error l otherwise, where l is the list of errors.
val retry : int -> (unit -> ('a, 'err) t) -> ('a, 'err list) tretry n f calls f at most n times, returning the first result of f () that doesn't fail. If f fails n times, retry n f fails with the list of successive errors.
module type MONAD = sig ... end
Conversions
val to_opt : ('a, _) t -> 'a optionConvert a result to an option.
val of_opt : 'a option -> ('a, string) tConvert an option to a result.
val to_seq : ('a, _) t -> 'a Stdlib.Seq.tRenamed from to_std_seq since 3.0.
- since
- 3.0
IO
\ No newline at end of file
diff --git a/dev/containers/Containers/index.html b/dev/containers/Containers/index.html
index 503fd40c..a1f2559b 100644
--- a/dev/containers/Containers/index.html
+++ b/dev/containers/Containers/index.html
@@ -1,2 +1,2 @@
-Containers (containers.Containers) Module Containers
Drop-In replacement to Stdlib
module Array = CCArraymodule Bool = CCBoolmodule Char = CCCharmodule Equal = CCEqualmodule Either = CCEithermodule Float = CCFloatmodule Format = CCFormatmodule Fun = CCFunmodule Hash = CCHashmodule Hashtbl : sig ... end
module Heap = CCHeapmodule Int = CCIntmodule Int32 = CCInt32module Int64 = CCInt64module IO = CCIOmodule List = CCListmodule Map = CCMapmodule Nativeint = CCNativeintmodule Option = CCOptmodule Ord = CCOrdmodule Pair = CCPairmodule Parse = CCParsemodule Random = CCRandommodule Ref = CCRefmodule Result = CCResultmodule Seq = CCSeqmodule Set = CCSetmodule String = CCStringmodule Vector = CCVectormodule Monomorphic = CCMonomorphicmodule Utf8_string = CCUtf8_stringmodule Sexp = CCSexpmodule Sexp_intf = CCSexp_intfmodule Canonical_sexp = CCCanonical_sexpmodule Stdlib = CCShims_.Stdlibinclude Monomorphic
Shadow unsafe functions and operators from Stdlib
val (=) : int -> int -> boolval (<>) : int -> int -> boolval (<) : int -> int -> boolval (>) : int -> int -> boolval (<=) : int -> int -> boolval (>=) : int -> int -> boolval compare : int -> int -> intval min : int -> int -> intval max : int -> int -> int
Infix operators for Floats
Shadow Dangerous Operators
\ No newline at end of file
+Containers (containers.Containers) Module Containers
Drop-In replacement to Stdlib
module Array = CCArraymodule Bool = CCBoolmodule Char = CCCharmodule Equal = CCEqualmodule Either = CCEithermodule Float = CCFloatmodule Format = CCFormatmodule Fun = CCFunmodule Hash = CCHashmodule Hashtbl : sig ... end
module Heap = CCHeapmodule Int = CCIntmodule Int32 = CCInt32module Int64 = CCInt64module IO = CCIOmodule List = CCListmodule Map = CCMapmodule Nativeint = CCNativeintmodule Option = CCOptionmodule Ord = CCOrdmodule Pair = CCPairmodule Parse = CCParsemodule Random = CCRandommodule Ref = CCRefmodule Result = CCResultmodule Seq = CCSeqmodule Set = CCSetmodule String = CCStringmodule Vector = CCVectormodule Monomorphic = CCMonomorphicmodule Utf8_string = CCUtf8_stringmodule Sexp = CCSexpmodule Sexp_intf = CCSexp_intfmodule Canonical_sexp = CCCanonical_sexpmodule Stdlib = CCShims_.Stdlibinclude Monomorphic
Shadow unsafe functions and operators from Stdlib
val (=) : int -> int -> boolval (<>) : int -> int -> boolval (<) : int -> int -> boolval (>) : int -> int -> boolval (<=) : int -> int -> boolval (>=) : int -> int -> boolval compare : int -> int -> intval min : int -> int -> intval max : int -> int -> int
Infix operators for Floats
Shadow Dangerous Operators
\ No newline at end of file
diff --git a/dev/containers/ContainersLabels/index.html b/dev/containers/ContainersLabels/index.html
index 775af3bf..46119397 100644
--- a/dev/containers/ContainersLabels/index.html
+++ b/dev/containers/ContainersLabels/index.html
@@ -1,2 +1,2 @@
-ContainersLabels (containers.ContainersLabels) Module ContainersLabels
Drop-In replacement to Stdlib
module Array = CCArrayLabelsmodule Bool = CCBoolmodule Char = CCCharmodule Equal = CCEqualLabelsmodule Either = CCEithermodule Float = CCFloatmodule Format = CCFormatmodule Fun = CCFunmodule Hash = CCHashmodule Hashtbl : sig ... end
module Heap = CCHeapmodule Int = CCIntmodule Int32 = CCInt32module Int64 = CCInt64module IO = CCIOmodule List = CCListLabelsmodule Map = CCMapmodule Nativeint = CCNativeintmodule Option = CCOptmodule Ord = CCOrdmodule Pair = CCPairmodule Parse = CCParsemodule Random = CCRandommodule Ref = CCRefmodule Result = CCResultmodule Seq = CCSeqmodule Set = CCSetmodule String = CCStringLabelsmodule Vector = CCVectormodule Monomorphic = CCMonomorphicmodule Utf8_string = CCUtf8_stringmodule Sexp = CCSexpmodule Sexp_intf = CCSexp_intfmodule Stdlib = CCShims_.Stdlibinclude Monomorphic
Shadow unsafe functions and operators from Stdlib
val (=) : int -> int -> boolval (<>) : int -> int -> boolval (<) : int -> int -> boolval (>) : int -> int -> boolval (<=) : int -> int -> boolval (>=) : int -> int -> boolval compare : int -> int -> intval min : int -> int -> intval max : int -> int -> int
Infix operators for Floats
Shadow Dangerous Operators
\ No newline at end of file
+ContainersLabels (containers.ContainersLabels) Module ContainersLabels
Drop-In replacement to Stdlib
module Array = CCArrayLabelsmodule Bool = CCBoolmodule Char = CCCharmodule Equal = CCEqualLabelsmodule Either = CCEithermodule Float = CCFloatmodule Format = CCFormatmodule Fun = CCFunmodule Hash = CCHashmodule Hashtbl : sig ... end
module Heap = CCHeapmodule Int = CCIntmodule Int32 = CCInt32module Int64 = CCInt64module IO = CCIOmodule List = CCListLabelsmodule Map = CCMapmodule Nativeint = CCNativeintmodule Option = CCOptionmodule Ord = CCOrdmodule Pair = CCPairmodule Parse = CCParsemodule Random = CCRandommodule Ref = CCRefmodule Result = CCResultmodule Seq = CCSeqmodule Set = CCSetmodule String = CCStringLabelsmodule Vector = CCVectormodule Monomorphic = CCMonomorphicmodule Utf8_string = CCUtf8_stringmodule Sexp = CCSexpmodule Sexp_intf = CCSexp_intfmodule Stdlib = CCShims_.Stdlibinclude Monomorphic
Shadow unsafe functions and operators from Stdlib
val (=) : int -> int -> boolval (<>) : int -> int -> boolval (<) : int -> int -> boolval (>) : int -> int -> boolval (<=) : int -> int -> boolval (>=) : int -> int -> boolval compare : int -> int -> intval min : int -> int -> intval max : int -> int -> int
Infix operators for Floats
Shadow Dangerous Operators
\ No newline at end of file
diff --git a/dev/containers/index.html b/dev/containers/index.html
index d8abe9f4..88b8c7a8 100644
--- a/dev/containers/index.html
+++ b/dev/containers/index.html
@@ -1,2 +1,2 @@
-index (containers.index) containers index
Library containers
This library exposes the following toplevel modules:
CCArrayCCArrayLabelsCCBoolCCCanonical_sexpCCCharCCEitherCCEqualCCEqualLabelsCCFloatCCFormatCCFunCCHashCCHashtblCCHeapCCIOCCIntCCInt32CCInt64CCListCCListLabelsCCMapCCNativeintCCOptCCOrdCCPairCCParseCCRandomCCRefCCResultCCSeqCCSetCCSexpCCSexp_intfCCSexp_lexCCShimsArrayLabels_CCShimsArray_CCShimsEither_CCShimsFormat_CCShimsFun_CCShimsInt_CCShimsList_CCShimsMkLetList_CCShimsMkLet_CCShims_CCStringCCStringLabelsCCUtf8_stringCCVectorContainersContainersLabels
Library containers.codegen
The entry point of this library is the module: Containers_codegen.
Library containers.monomorphic
This library exposes the following toplevel modules:
Library containers.top
The entry point of this library is the module: Containers_top.
Library containers.unix
The entry point of this library is the module: CCUnix.
\ No newline at end of file
+index (containers.index) containers index
Library containers
This library exposes the following toplevel modules:
CCArrayCCArrayLabelsCCBoolCCCanonical_sexpCCCharCCEitherCCEqualCCEqualLabelsCCFloatCCFormatCCFunCCHashCCHashtblCCHeapCCIOCCIntCCInt32CCInt64CCListCCListLabelsCCMapCCNativeintCCOptCCOptionCCOrdCCPairCCParseCCRandomCCRefCCResultCCSeqCCSetCCSexpCCSexp_intfCCSexp_lexCCShimsArrayLabels_CCShimsArray_CCShimsEither_CCShimsFormat_CCShimsFun_CCShimsInt_CCShimsList_CCShimsMkLetList_CCShimsMkLet_CCShims_CCStringCCStringLabelsCCUtf8_stringCCVectorContainersContainersLabels
Library containers.codegen
The entry point of this library is the module: Containers_codegen.
Library containers.monomorphic
This library exposes the following toplevel modules:
Library containers.top
The entry point of this library is the module: Containers_top.
Library containers.unix
The entry point of this library is the module: CCUnix.
\ No newline at end of file