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
|
||||
(* default implem for some operators *)
|
||||
let ( |> ) x f = f x
|
||||
let ( @@ ) f x = f x
|
||||
let ( |> ) = CCShims_.Stdlib.( |> )
|
||||
let ( @@ ) = CCShims_.Stdlib.( @@ )
|
||||
let ( %> ) = compose
|
||||
let ( % ) f g x = f (g x)
|
||||
let[@inline] ( % ) f g x = f (g x)
|
||||
|
||||
[@@@ifge 4.8]
|
||||
|
||||
let ( let@ ) = ( @@ )
|
||||
|
||||
[@@@endif]
|
||||
end
|
||||
|
||||
include Infix
|
||||
|
|
@ -99,7 +105,8 @@ end) =
|
|||
struct
|
||||
type 'a t = X.t -> 'a
|
||||
|
||||
let return x _ = x
|
||||
let ( >|= ) f g x = g (f x)
|
||||
let ( >>= ) f g x = g (f x) x
|
||||
let[@inline] return x _ = x
|
||||
let[@inline] ( >|= ) f g x = g (f x)
|
||||
let[@inline] ( >>= ) f g x = g (f x) x
|
||||
end
|
||||
[@@inline]
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ include module type of Fun
|
|||
|
||||
[@@@else_]
|
||||
|
||||
(* port from stdlib *)
|
||||
|
||||
external id : 'a -> 'a = "%identity"
|
||||
(** This is an API imitating the new standard Fun module *)
|
||||
|
||||
|
|
@ -99,6 +101,15 @@ module Infix : sig
|
|||
|
||||
val ( % ) : ('b -> 'c) -> ('a -> 'b) -> 'a -> 'c
|
||||
(** [(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
|
||||
|
||||
include module type of Infix
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue