predicate combinators: and_p and or_p

This commit is contained in:
Ben Bellick 2024-08-24 10:26:01 -05:00
parent 65fc920427
commit df0e442956
2 changed files with 14 additions and 0 deletions

View file

@ -8,6 +8,10 @@ include Sys
include Stdlib include Stdlib
include Fun include Fun
let[@inline] and_p f g x = (f x) && (g x)
let[@inline] or_p f g x = (f x) || (g x)
let[@inline] compose f g x = g (f 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] compose_binop f g x y = g (f x) (f y)
let[@inline] curry f x y = f (x, y) let[@inline] curry f x y = f (x, y)

View file

@ -5,6 +5,16 @@
include module type of Fun include module type of Fun
(** @inline *) (** @inline *)
val and_p : ('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_p : ('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 val compose : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c
(** [compose f g x] is [g (f x)]. Composition. *) (** [compose f g x] is [g (f x)]. Composition. *)