From 8e6002040a1ea682661bf3d1bbd4eabc80f8927d Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Fri, 5 Jun 2020 00:03:46 +0200 Subject: [PATCH] utils: Add 0-1->boolean. --- utils.rkt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/utils.rkt b/utils.rkt index 7d13118..1ac2e9e 100644 --- a/utils.rkt +++ b/utils.rkt @@ -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)))