utils: Add 0-1->boolean.

This commit is contained in:
Sergiu Ivanov 2020-06-05 00:03:46 +02:00
parent 83dd673df9
commit 8e6002040a

View file

@ -49,7 +49,8 @@
[cartesian-product/stream (->* () #:rest (listof stream?) stream?)]
[boolean-power (-> number? (listof (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
(contract-out [variable-mapping? contract?]
[string-variable-mapping? contract?]
@ -705,3 +706,12 @@
(test-case "any->0-1"
(check-equal? (any->0-1 #t) 1)
(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)))