Skip to content

Commit 2aa8416

Browse files
committed
CCFun(cleanup): align CCFun.compose with the stdlib
Conditionally define CCFun.compose and align its definition with the stdlib. The arguments are now swapped.
1 parent 931b28e commit 2aa8416

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Changelog
22

33
## main
4-
- change the semantic of CCFloat.{min,max} with respect to NaN to follow the Stdlib
5-
- change the semantic of CCInt.rem with respect to negative number to follow the Stdlib
4+
- breaking: invert the argument of CCFun.compose to align it with the Stdlib
5+
- breaking: change the semantic of CCFloat.{min,max} with respect to NaN to follow the Stdlib
6+
- breaking: change the semantic of CCInt.rem with respect to negative number to follow the Stdlib
67

78
## 3.15
89

src/core/CCFun.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ include Fun
1010

1111
let[@inline] and_pred f g x = f x && g x
1212
let[@inline] or_pred f g x = f x || g x
13-
let[@inline] compose f g x = g (f x)
13+
14+
[@@@iflt 5.2]
15+
16+
let[@inline] compose f g x = f (g x)
17+
18+
[@@@endif]
19+
1420
let[@inline] compose_binop f g x y = g (f x) (f y)
1521
let[@inline] curry f x y = f (x, y)
1622
let[@inline] uncurry f (x, y) = f x y
@@ -63,7 +69,7 @@ let rec iterate n f x =
6369

6470
module Infix = struct
6571
(* default implem for some operators *)
66-
let ( %> ) = compose
72+
let ( %> ) f g = compose g f
6773
let[@inline] ( % ) f g x = f (g x)
6874
let ( let@ ) = ( @@ )
6975
let ( ||> ) (a, b) f = f a b

src/core/CCFun.mli

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ val or_pred : ('a -> bool) -> ('a -> bool) -> 'a -> bool
1717
@since 3.13.1
1818
*)
1919

20-
val compose : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c
21-
(** [compose f g x] is [g (f x)]. Composition. *)
20+
[@@@iflt 5.2]
21+
22+
val compose : ('b -> 'c) -> ('a -> 'b) -> 'a -> 'c
23+
(** [compose f g x] is [f (g x)]. Composition.
24+
@since NEXT_RELEASE arguments are inversted *)
25+
26+
[@@@endif]
2227

2328
val compose_binop : ('a -> 'b) -> ('b -> 'b -> 'c) -> 'a -> 'a -> 'c
2429
(** [compose_binop f g] is [fun x y -> g (f x) (f y)].
@@ -84,7 +89,8 @@ val iterate : int -> ('a -> 'a) -> 'a -> 'a
8489

8590
module Infix : sig
8691
val ( %> ) : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c
87-
(** [(f %> g) x] or [(%>) f g x] is [g (f x)]. Alias to [compose]. *)
92+
(** [(f %> g) x] or [(%>) f g x] is [g (f x)]. Infix version of [compose].
93+
The order of the arguments of [%>] and {!compose} are inverted. *)
8894

8995
val ( % ) : ('b -> 'c) -> ('a -> 'b) -> 'a -> 'c
9096
(** [(f % g) x] or [(%) f g x] is [f (g x)]. Mathematical composition. *)

0 commit comments

Comments
 (0)