Skip to content

Instantly share code, notes, and snippets.

@sritchie
Created September 9, 2011 17:59
Show Gist options
  • Select an option

  • Save sritchie/1206888 to your computer and use it in GitHub Desktop.

Select an option

Save sritchie/1206888 to your computer and use it in GitHub Desktop.
(deffilterop [always-true [some-bool]]
[x]
(or some-bool true))
(?<- (stdout)
[?value]
([[1]] ?value)
(always-true [true] ?value))
RESULTS
-----------------------
1 true
-----------------------
(?<- (stdout)
[?value ?bool]
([[1]] ?value)
(always-true [false] ?value :> ?bool))
RESULTS
-----------------------
1 false
-----------------------
(?<- (stdout)
[?value ?bool]
([[1]] ?value)
(always-true [nil] ?value :> ?bool))
RESULTS
-----------------------
1 true
-----------------------
;; defmapcatop deals with this just fine
(defmapcatop [always-returns [some-bool]]
[x]
(when (or some-bool true)
[x]))
(?<- (stdout)
[?ret]
([[1]] ?value)
(always-returns [false] ?value :> ?ret))
RESULTS
-----------------------
1
-----------------------
(?<- (stdout)
[?ret]
([[1]] ?value)
(always-returns [true] ?value :> ?ret))
RESULTS
-----------------------
1
-----------------------
;; More funky stuff -- that println prints "false? true", which is what we want.
;; But the query still returns [1 false].
(deffilterop [always-true [some-bool]]
[x]
(println "false?" (= some-bool false))
(or some-bool true))
(?<- (stdout)
[?value ?bool]
([[1]] ?value)
(always-true [false] ?value :> ?bool))
RESULTS
-----------------------
1 false
-----------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment