Skip to content

Commit

Permalink
Fix gitignore and add truthiness transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfirth committed Feb 24, 2015
1 parent 1a425cb commit 2166b92
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
12 changes: 7 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*\compiled\*
*\*.bak
*\*.html
*\*.css
*\*.js
**/compiled/*
**.bak
**.html
**.css
**.js
**.1
**.2
10 changes: 10 additions & 0 deletions predicates/logic.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(require "contract-helpers.rkt")

(provide (contract-out [true? predicate/c]
[without-truthiness (-> procedure? procedure?)]
[and? predicate*->/c]
[or? predicate*->/c]
[not? predicate->/c]
Expand Down Expand Up @@ -46,3 +47,12 @@
(check-true (first-num-or-second-sym? 4 'baz))
(check-false (first-num-or-second-sym? "smurf" '())))

;; Helper for dealing with truthy predicates

(define (without-truthiness f)
(compose true? f))

(module+ test
(define member? (without-truthiness member))
(check-true (member? 'a '(a b c)))
(check-false (member? 1 '(a b c))))
11 changes: 11 additions & 0 deletions predicates/predicates.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,17 @@ source code: @url["https://github.com/jackfirth/predicates"]
(true? 'foo)
]}

@defproc[(without-truthiness [f proc?]) proc?]{
Returns a procedure that's like @racket[f], but returns either @racket[#t] or
@racket[#f] based on whether @racket[f] returns false. Essentially, this procedure
turns functions that rely on returning "truthy" values into function that only
return a boolean.
@module-examples[
(define member? (without-truthiness member))
(member? 1 '(1 2 3))
(member? 'foo '(1 2 3))
]}

@defproc[(in-range? [low real?] [high real?] [exclusive? boolean? #f]) (-> any? boolean?)]{
Returns a predicate that determins in its input is a real number between @racket[low]
and @racket[high]. If @racket[exclusive?] is @racket[#t], then values @racket[=] to
Expand Down

0 comments on commit 2166b92

Please sign in to comment.