From 84a82606d0d9ebda5926af14244c47b63c0dcf48 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 29 Sep 2014 08:30:26 -0700 Subject: [PATCH] count_if --- csp/utils.rkt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/csp/utils.rkt b/csp/utils.rkt index a48d6a62..4b88ea4f 100644 --- a/csp/utils.rkt +++ b/csp/utils.rkt @@ -1,3 +1,12 @@ #lang racket/base +(require racket/list racket/bool) -(provide (all-defined-out)) \ No newline at end of file +(provide (all-defined-out)) + +(module+ test (require rackunit)) + +(define (count_if pred xs) + (length (filter-not false? (map pred xs)))) + +(module+ test + (check-equal? (count_if procedure? (list 42 null max min)) 2)) \ No newline at end of file