You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
typesetting/csp/utils.rkt

22 lines
605 B
Racket

10 years ago
#lang racket/base
10 years ago
(require racket/list racket/bool)
10 years ago
10 years ago
(provide (all-defined-out))
(module+ test (require rackunit))
(define (count_if pred xs)
10 years ago
;; Count the number of elements of seq for which the predicate is true.
10 years ago
(length (filter-not false? (map pred xs))))
(module+ test
10 years ago
(check-equal? (count_if procedure? (list 42 null max min)) 2))
(define (find_if pred xs)
;; If there is an element of seq that satisfies predicate; return it.
(or (findf pred xs) null))
(module+ test
(check-equal? (find_if procedure? (list 3 min max)) min)
(check-equal? (find_if procedure? (list 1 2 3)) null))