mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
feat: put the let operators inside the Infix modules when relevant
This commit is contained in:
parent
bf0227d404
commit
b2d9e69042
10 changed files with 86 additions and 70 deletions
|
|
@ -351,12 +351,6 @@ let bsearch ~cmp k a =
|
|||
bsearch ~cmp:CCInt.compare 3 [| |] = `Empty
|
||||
*)
|
||||
|
||||
let (>>=) a f = flat_map f a
|
||||
|
||||
let (>>|) a f = map f a
|
||||
|
||||
let (>|=) a f = map f a
|
||||
|
||||
let for_all p a =
|
||||
let rec aux i =
|
||||
i = Array.length a || (p a.(i) && aux (i+1))
|
||||
|
|
@ -716,13 +710,22 @@ let sort_generic (type arr)(type elt)
|
|||
|
||||
|
||||
module Infix = struct
|
||||
let (>>=) = (>>=)
|
||||
let (>>|) = (>>|)
|
||||
let (>|=) = (>|=)
|
||||
let (>>=) a f = flat_map f a
|
||||
let (>>|) a f = map f a
|
||||
let (>|=) a f = map f a
|
||||
let (--) = (--)
|
||||
let (--^) = (--^)
|
||||
|
||||
include CCShimsMkLet_.Make(struct
|
||||
type 'a t = 'a array
|
||||
let (>>=) = (>>=)
|
||||
let (>|=) = (>|=)
|
||||
let monoid_product a1 a2 = monoid_product (fun x y->x,y) a1 a2
|
||||
end)
|
||||
end
|
||||
|
||||
include Infix
|
||||
|
||||
|
||||
(* test consistency of interfaces *)
|
||||
(*$inject
|
||||
|
|
@ -738,9 +741,3 @@ end
|
|||
(*$R
|
||||
ignore (module CCArray : LL)
|
||||
*)
|
||||
|
||||
include CCShimsMkLet_.Make(struct
|
||||
type 'a t = 'a array
|
||||
include Infix
|
||||
let monoid_product a1 a2 = monoid_product (fun x y->x,y) a1 a2
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -376,6 +376,10 @@ module Infix : sig
|
|||
val (--^) : int -> int -> int t
|
||||
(** [x --^ y] creates an array containing integers in the range [x .. y]. Right bound excluded.
|
||||
@since 0.17 *)
|
||||
|
||||
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
||||
@since NEXT_RELEASE *)
|
||||
include CCShimsMkLet_.S with type 'a t_let := 'a array
|
||||
end
|
||||
|
||||
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
||||
|
|
|
|||
|
|
@ -377,6 +377,10 @@ module Infix : sig
|
|||
val (--^) : int -> int -> int t
|
||||
(** [x --^ y] creates an array containing integers in the range [x .. y]. Right bound excluded.
|
||||
@since 0.17 *)
|
||||
|
||||
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
||||
@since NEXT_RELEASE *)
|
||||
include CCShimsMkLet_.S with type 'a t_let := 'a array
|
||||
end
|
||||
|
||||
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
||||
|
|
|
|||
|
|
@ -123,8 +123,6 @@ let map f l =
|
|||
List.rev (List.rev_map f l) = map f l)
|
||||
*)
|
||||
|
||||
let (>|=) l f = map f l
|
||||
|
||||
let direct_depth_append_ = 10_000
|
||||
|
||||
let cons x l = x::l
|
||||
|
|
@ -548,10 +546,6 @@ let split l =
|
|||
|
||||
let return x = [x]
|
||||
|
||||
let (>>=) l f = flat_map f l
|
||||
|
||||
let (<$>) = map
|
||||
|
||||
let pure = return
|
||||
|
||||
let (<*>) funs l = product (fun f x -> f x) funs l
|
||||
|
|
@ -1710,20 +1704,23 @@ let of_klist l =
|
|||
direct direct_depth_default_ l
|
||||
|
||||
module Infix = struct
|
||||
let (>|=) = (>|=)
|
||||
let (>|=) l f = map f l
|
||||
let (>>=) l f = flat_map f l
|
||||
let (@) = (@)
|
||||
let (<*>) = (<*>)
|
||||
let (<$>) = (<$>)
|
||||
let (>>=) = (>>=)
|
||||
let (<$>) = map
|
||||
let (--) = (--)
|
||||
let (--^) = (--^)
|
||||
|
||||
include CCShimsMkLet_.Make(struct
|
||||
type 'a t = 'a list
|
||||
let (>|=) = (>|=)
|
||||
let (>>=) = (>>=)
|
||||
let monoid_product l1 l2 = product (fun x y -> x,y) l1 l2
|
||||
end)
|
||||
end
|
||||
|
||||
include CCShimsMkLet_.Make(struct
|
||||
type 'a t = 'a list
|
||||
include Infix
|
||||
let monoid_product l1 l2 = product (fun x y -> x,y) l1 l2
|
||||
end)
|
||||
include Infix
|
||||
|
||||
(** {2 IO} *)
|
||||
|
||||
|
|
|
|||
|
|
@ -738,9 +738,12 @@ module Infix : sig
|
|||
(** Infix alias for [range]. Bounds included. *)
|
||||
|
||||
val (--^) : int -> int -> int t
|
||||
(** Infix alias for [range']. Second bound excluded. *)
|
||||
(** Infix alias for [range']. Second bound excluded.
|
||||
@since 0.17 *)
|
||||
|
||||
(** @since 0.17 *)
|
||||
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
||||
@since NEXT_RELEASE *)
|
||||
include CCShimsMkLet_.S with type 'a t_let := 'a list
|
||||
end
|
||||
|
||||
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
||||
|
|
|
|||
|
|
@ -736,9 +736,12 @@ module Infix : sig
|
|||
(** Infix alias for [range]. Bounds included. *)
|
||||
|
||||
val (--^) : int -> int -> int t
|
||||
(** Infix alias for [range']. Second bound excluded. *)
|
||||
(** Infix alias for [range']. Second bound excluded.
|
||||
@since 0.17 *)
|
||||
|
||||
(** @since 0.17 *)
|
||||
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
||||
@since NEXT_RELEASE *)
|
||||
include CCShimsMkLet_.S with type 'a t_let := 'a list
|
||||
end
|
||||
|
||||
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
||||
|
|
|
|||
|
|
@ -38,8 +38,6 @@ let equal f o1 o2 = match o1, o2 with
|
|||
|
||||
let return x = Some x
|
||||
|
||||
let (>|=) x f = map f x
|
||||
|
||||
let (>>=) o f = match o with
|
||||
| None -> None
|
||||
| Some x -> f x
|
||||
|
|
@ -55,8 +53,6 @@ let (<*>) f x = match f, x with
|
|||
| _, None -> None
|
||||
| Some f, Some x -> Some (f x)
|
||||
|
||||
let (<$>) = map
|
||||
|
||||
let or_ ~else_ a = match a with
|
||||
| None -> else_
|
||||
| Some _ -> a
|
||||
|
|
@ -163,13 +159,24 @@ let of_result = function
|
|||
| Ok x -> Some x
|
||||
|
||||
module Infix = struct
|
||||
let (>|=) = (>|=)
|
||||
let (>|=) x f = map f x
|
||||
let (>>=) = (>>=)
|
||||
let (<*>) = (<*>)
|
||||
let (<$>) = (<$>)
|
||||
let (<$>) = map
|
||||
let (<+>) = (<+>)
|
||||
|
||||
include CCShimsMkLet_.Make(struct
|
||||
type 'a t = 'a option
|
||||
let (>|=) = (>|=)
|
||||
let (>>=) = (>>=)
|
||||
let monoid_product o1 o2 = match o1, o2 with
|
||||
| Some x, Some y -> Some (x,y)
|
||||
| _ -> None
|
||||
end)
|
||||
end
|
||||
|
||||
include Infix
|
||||
|
||||
type 'a sequence = ('a -> unit) -> unit
|
||||
type 'a gen = unit -> 'a option
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
|
@ -238,11 +245,3 @@ let return_if b x =
|
|||
return_if false 1 = None
|
||||
return_if true 1 = Some 1
|
||||
*)
|
||||
|
||||
include CCShimsMkLet_.Make(struct
|
||||
type 'a t = 'a option
|
||||
include Infix
|
||||
let monoid_product o1 o2 = match o1, o2 with
|
||||
| Some x, Some y -> Some (x,y)
|
||||
| _ -> None
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -154,8 +154,17 @@ module Infix : sig
|
|||
val (<+>) : 'a t -> 'a t -> 'a t
|
||||
(** [a <+> b] is [a] if [a] is [Some _], [b] otherwise. *)
|
||||
|
||||
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
||||
@since NEXT_RELEASE *)
|
||||
include CCShimsMkLet_.S with type 'a t_let := 'a option
|
||||
|
||||
end
|
||||
|
||||
|
||||
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
||||
@since NEXT_RELEASE *)
|
||||
include CCShimsMkLet_.S with type 'a t_let := 'a option
|
||||
|
||||
(** {2 Conversion and IO} *)
|
||||
|
||||
val to_list : 'a t -> 'a list
|
||||
|
|
@ -199,7 +208,3 @@ val to_seq : 'a t -> 'a sequence
|
|||
@deprecated use {!to_iter} instead *)
|
||||
|
||||
val pp : 'a printer -> 'a t printer
|
||||
|
||||
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
||||
@since NEXT_RELEASE *)
|
||||
include CCShimsMkLet_.S with type 'a t_let := 'a option
|
||||
|
|
|
|||
|
|
@ -124,10 +124,6 @@ let flat_map f e = match e with
|
|||
| Ok x -> f x
|
||||
| Error s -> Error s
|
||||
|
||||
let (>|=) e f = map f e
|
||||
|
||||
let (>>=) e f = flat_map f e
|
||||
|
||||
let equal ~err eq a b = match a, b with
|
||||
| Ok x, Ok y -> eq x y
|
||||
| Error s, Error s' -> err s s'
|
||||
|
|
@ -269,11 +265,23 @@ let retry n f =
|
|||
(** {2 Infix} *)
|
||||
|
||||
module Infix = struct
|
||||
let (>>=) = (>>=)
|
||||
let (>|=) = (>|=)
|
||||
let (>|=) e f = map f e
|
||||
let (>>=) e f = flat_map f e
|
||||
let (<*>) = (<*>)
|
||||
|
||||
include CCShimsMkLet_.Make2(struct
|
||||
type ('a,'e) t = ('a,'e) result
|
||||
let (>>=) = (>>=)
|
||||
let (>|=) = (>|=)
|
||||
let monoid_product x1 x2 = match x1, x2 with
|
||||
| Ok x, Ok y -> Ok (x,y)
|
||||
| Error e, _ -> Error e
|
||||
| _, Error e -> Error e
|
||||
end)
|
||||
end
|
||||
|
||||
include Infix
|
||||
|
||||
(** {2 Monadic Operations} *)
|
||||
|
||||
module type MONAD = sig
|
||||
|
|
@ -338,12 +346,3 @@ let pp pp_x fmt e = match e with
|
|||
let pp' pp_x pp_e fmt e = match e with
|
||||
| Ok x -> Format.fprintf fmt "@[ok(@,%a)@]" pp_x x
|
||||
| Error s -> Format.fprintf fmt "@[error(@,%a)@]" pp_e s
|
||||
|
||||
include CCShimsMkLet_.Make2(struct
|
||||
type ('a,'e) t = ('a,'e) result
|
||||
include Infix
|
||||
let monoid_product x1 x2 = match x1, x2 with
|
||||
| Ok x, Ok y -> Ok (x,y)
|
||||
| Error e, _ -> Error e
|
||||
| _, Error e -> Error e
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -179,8 +179,17 @@ module Infix : sig
|
|||
(** [a <*> 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 NEXT_RELEASE *)
|
||||
include CCShimsMkLet_.S2 with type ('a,'e) t_let2 := ('a,'e) result
|
||||
end
|
||||
|
||||
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
||||
@since NEXT_RELEASE *)
|
||||
include CCShimsMkLet_.S2 with type ('a,'e) t_let2 := ('a,'e) result
|
||||
|
||||
|
||||
(** {2 Collections} *)
|
||||
|
||||
val flatten_l : ('a, 'err) t list -> ('a list, 'err) t
|
||||
|
|
@ -253,7 +262,3 @@ val pp : 'a printer -> ('a, string) t printer
|
|||
|
||||
val pp': 'a printer -> 'e printer -> ('a, 'e) t printer
|
||||
(** Printer that is generic on the error type. *)
|
||||
|
||||
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
||||
@since NEXT_RELEASE *)
|
||||
include CCShimsMkLet_.S2 with type ('a,'e) t_let2 := ('a,'e) result
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue