Skip to content

Commit d24a051

Browse files
committed
Prelude: + F1
1 parent 9551483 commit d24a051

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

prelude.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ let ($) f g = fun x -> f (g x)
77
let ($$) f g = fun x y -> f (g x) (g y)
88
let (!!) = Lazy.force
99

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+
1015
external id : 'a -> 'a = "%identity"
1116
external identity : 'a -> 'a = "%identity"
1217
let flip f x y = f y x

prelude.mli

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ val ( $ ) : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b
99
(** 2-function composition : [f $$ g] is equivalent to [(fun x y -> f (g x) (g y))] *)
1010
val ( $$ ) : ('a -> 'a -> 'b) -> ('c -> 'a) -> 'c -> 'c -> 'b
1111

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+
1221
(** identity *)
1322
val id : 'a -> 'a
1423

0 commit comments

Comments
 (0)