A peer-to-peer stack for code collaboration
{:module 'prelude/bool
:doc "Functions for dealing with truthiness and #f."
:exports '[not and all and-predicate]}
;; boolean functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; not
(def not
"True if `x` is `#f`, false otherwise."
(fn [x] (if x #f #t)))
;; and
(def and
"Returns `y` if `x` is not `#f`, otherwise returns `x`"
(fn [x y]
(if x y x)))
(:test "and"
[ (and #t #t) ==> #t ]
[ (and #t #f) ==> #f ]
[ (and #f #t) ==> #f ]
[ (and #f #f) ==> #f ]
)
;; all
(def all
"Checks that all the items of a list are truthy."
(fn [xs] (foldr and #t xs)))
(:test "all"
[ (all '()) ==> #t ]
[ (all '(#t)) ==> #t ]
[ (all '(#f)) ==> #f ]
[ (all '(#t #t #t #t)) ==> #t ]
[ (all '(#t #t #f #t)) ==> #f ]
)
(def and-predicate
"Pointwise conjunction of predicates."
(fn [f g] (fn [x] (and (f x) (g x)))))