utils: Add 0-1->boolean.
This commit is contained in:
parent
83dd673df9
commit
8e6002040a
1 changed files with 11 additions and 1 deletions
12
utils.rkt
12
utils.rkt
|
@ -49,7 +49,8 @@
|
||||||
[cartesian-product/stream (->* () #:rest (listof stream?) stream?)]
|
[cartesian-product/stream (->* () #:rest (listof stream?) stream?)]
|
||||||
[boolean-power (-> number? (listof (listof boolean?)))]
|
[boolean-power (-> number? (listof (listof boolean?)))]
|
||||||
[boolean-power/stream (-> number? (stream/c (listof boolean?)))]
|
[boolean-power/stream (-> number? (stream/c (listof boolean?)))]
|
||||||
[any->0-1 (-> any/c (or/c 0 1))])
|
[any->0-1 (-> any/c (or/c 0 1))]
|
||||||
|
[0-1->boolean (-> (or/c 0 1) boolean?)])
|
||||||
;; Contracts
|
;; Contracts
|
||||||
(contract-out [variable-mapping? contract?]
|
(contract-out [variable-mapping? contract?]
|
||||||
[string-variable-mapping? contract?]
|
[string-variable-mapping? contract?]
|
||||||
|
@ -705,3 +706,12 @@
|
||||||
(test-case "any->0-1"
|
(test-case "any->0-1"
|
||||||
(check-equal? (any->0-1 #t) 1)
|
(check-equal? (any->0-1 #t) 1)
|
||||||
(check-equal? (any->0-1 #f) 0)))
|
(check-equal? (any->0-1 #f) 0)))
|
||||||
|
|
||||||
|
;;; Converts 0 to #f and 1 to #t
|
||||||
|
(define (0-1->boolean x)
|
||||||
|
(case x [(0) #f] [else #t]))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "0-1->boolean"
|
||||||
|
(check-equal? (0-1->boolean 0) #f)
|
||||||
|
(check-equal? (0-1->boolean 1) #t)))
|
||||||
|
|
Loading…
Reference in a new issue