Skip to content

Commit

Permalink
Merge pull request #458 from benbellick/add-predicate-combinator
Browse files Browse the repository at this point in the history
predicate combinators: and_p and or_p
  • Loading branch information
c-cube authored Sep 3, 2024
2 parents 65fc920 + c6cb572 commit 5abb635
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/CCFun.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ include Sys
include Stdlib
include Fun

let[@inline] and_pred f g x = f x && g x
let[@inline] or_pred f g x = f x || g x
let[@inline] compose f g x = g (f x)
let[@inline] compose_binop f g x y = g (f x) (f y)

let[@inline] curry f x y = f (x, y)
let[@inline] uncurry f (x, y) = f x y

Expand Down
10 changes: 10 additions & 0 deletions src/core/CCFun.mli
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
include module type of Fun
(** @inline *)

val and_pred : ('a -> bool) -> ('a -> bool) -> 'a -> bool
(** [and_p f g x] is [(f x) && (g x)].
Produces a predicate which is a conjunction of the two predicates.
*)

val or_pred : ('a -> bool) -> ('a -> bool) -> 'a -> bool
(** [or_p f g x] is [(f x) || (g x)].
Produces a predicate which is a disjunction of the two predicates.
*)

val compose : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c
(** [compose f g x] is [g (f x)]. Composition. *)

Expand Down

0 comments on commit 5abb635

Please sign in to comment.