From 1bb8b90e0bb3f842767d8d180b2d236744b5b9d1 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 29 Sep 2014 16:49:50 -0700 Subject: [PATCH] `every` --- csp/utils.rkt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/csp/utils.rkt b/csp/utils.rkt index 6024fa02..510ccd4c 100644 --- a/csp/utils.rkt +++ b/csp/utils.rkt @@ -5,6 +5,8 @@ (module+ test (require rackunit)) + + (define (count_if pred xs) ;; Count the number of elements of seq for which the predicate is true. (length (filter-not false? (map pred xs)))) @@ -19,4 +21,12 @@ (module+ test (check-equal? (find_if procedure? (list 3 min max)) min) (check-equal? (find_if procedure? (list 1 2 3)) null)) - \ No newline at end of file + + +(define (every pred xs) + ;;;True if every element of seq satisfies predicate. + (andmap pred xs)) + +(module+ test + (check-true (every procedure? (list min max))) + (check-false (every procedure? (list min 3)))) \ No newline at end of file