stxge/mod/predicate.scm

23 lines
916 B
Scheme

;;; predicate.scm
;; Some helpful functions relating to predicates
(define-module (predicate)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
#:export (conjoin conjoin-with-value conjoin/v
disjoin disjoin-with-value disjoin/v))
(define (conjoin . predicates) (lambda (x) (every (cut <> x) predicates)))
;; Generate a function that is effectively (and (pred1 val) (pred2 val) ...)
(define (disjoin . predicates) (lambda (x) (any (cut <> x) predicates)))
;; Generate a function that is effectively (or (pred1 val) (pred2 val) ...)
(define (conjoin-with-value value . predicates) ((apply conjoin predicates) value))
(define (disjoin-with-value value . predicates) ((apply disjoin predicates) value))
;; Shorthand to directly pass a value to a series of predicates
(define conjoin/v conjoin-with-value)
(define disjoin/v disjoin-with-value)
;; Even further shorthand for the above