File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,11 @@ let ($) f g = fun x -> f (g x)
7
7
let ($$) f g = fun x y -> f (g x) (g y)
8
8
let (!! ) = Lazy. force
9
9
10
+ module F1 = struct
11
+ let (@@) f g = fun x -> f @@ g @@ x
12
+ let (|>) f g = fun x -> x |> f |> g
13
+ end
14
+
10
15
external id : 'a -> 'a = " %identity"
11
16
external identity : 'a -> 'a = " %identity"
12
17
let flip f x y = f y x
Original file line number Diff line number Diff line change @@ -9,6 +9,15 @@ val ( $ ) : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b
9
9
(* * 2-function composition : [f $$ g] is equivalent to [(fun x y -> f (g x) (g y))] *)
10
10
val ( $$ ) : ('a -> 'a -> 'b) -> ('c -> 'a) -> 'c -> 'c -> 'b
11
11
12
+ (* * 1-argument function composition combinators that allow quickly switching to or from point-free chained function pipeline
13
+ e.g. [let inc s = string_of_int @@ (+) 1 @@ int_of_string s] vs [let inc = F1.(string_of_int @@ (+) 1 @@ int_of_string)]
14
+ and similarly [let inc = F1.(int_of_string |> (+) 1 |> string_of_int)]
15
+ *)
16
+ module F1 : sig
17
+ val ( @@ ) : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b
18
+ val ( |> ) : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c
19
+ end
20
+
12
21
(* * identity *)
13
22
val id : 'a -> 'a
14
23
You can’t perform that action at this time.
0 commit comments