mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
add CCFun.(let@) (if OCaml >= 4.08)
This commit is contained in:
parent
b1c39832aa
commit
735729c329
2 changed files with 24 additions and 6 deletions
|
|
@ -85,10 +85,16 @@ let rec iterate n f x =
|
||||||
|
|
||||||
module Infix = struct
|
module Infix = struct
|
||||||
(* default implem for some operators *)
|
(* default implem for some operators *)
|
||||||
let ( |> ) x f = f x
|
let ( |> ) = CCShims_.Stdlib.( |> )
|
||||||
let ( @@ ) f x = f x
|
let ( @@ ) = CCShims_.Stdlib.( @@ )
|
||||||
let ( %> ) = compose
|
let ( %> ) = compose
|
||||||
let ( % ) f g x = f (g x)
|
let[@inline] ( % ) f g x = f (g x)
|
||||||
|
|
||||||
|
[@@@ifge 4.8]
|
||||||
|
|
||||||
|
let ( let@ ) = ( @@ )
|
||||||
|
|
||||||
|
[@@@endif]
|
||||||
end
|
end
|
||||||
|
|
||||||
include Infix
|
include Infix
|
||||||
|
|
@ -99,7 +105,8 @@ end) =
|
||||||
struct
|
struct
|
||||||
type 'a t = X.t -> 'a
|
type 'a t = X.t -> 'a
|
||||||
|
|
||||||
let return x _ = x
|
let[@inline] return x _ = x
|
||||||
let ( >|= ) f g x = g (f x)
|
let[@inline] ( >|= ) f g x = g (f x)
|
||||||
let ( >>= ) f g x = g (f x) x
|
let[@inline] ( >>= ) f g x = g (f x) x
|
||||||
end
|
end
|
||||||
|
[@@inline]
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ include module type of Fun
|
||||||
|
|
||||||
[@@@else_]
|
[@@@else_]
|
||||||
|
|
||||||
|
(* port from stdlib *)
|
||||||
|
|
||||||
external id : 'a -> 'a = "%identity"
|
external id : 'a -> 'a = "%identity"
|
||||||
(** This is an API imitating the new standard Fun module *)
|
(** This is an API imitating the new standard Fun module *)
|
||||||
|
|
||||||
|
|
@ -99,6 +101,15 @@ module Infix : sig
|
||||||
|
|
||||||
val ( % ) : ('b -> 'c) -> ('a -> 'b) -> 'a -> 'c
|
val ( % ) : ('b -> 'c) -> ('a -> 'b) -> 'a -> 'c
|
||||||
(** [(f % g) x] or [(%) f g x] is [f (g x)]. Mathematical composition. *)
|
(** [(f % g) x] or [(%) f g x] is [f (g x)]. Mathematical composition. *)
|
||||||
|
|
||||||
|
[@@@ifge 4.8]
|
||||||
|
|
||||||
|
val ( let@ ) : ('a -> 'b) -> 'a -> 'b
|
||||||
|
(** [let@ x = foo in bar] is the equivalent of [foo @@ fun x -> bar].
|
||||||
|
It can be very useful for resource management, alongside with {!protect}.
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
[@@@endif]
|
||||||
end
|
end
|
||||||
|
|
||||||
include module type of Infix
|
include module type of Infix
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue