Created
January 7, 2012 02:37
-
-
Save noahlz/1573558 to your computer and use it in GitHub Desktop.
idomatic search using persistent set in Clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(re-find #"A|B|C" "B") ;; Two Problems | |
;=> "B" | |
(some #(= % "B") ["A" "B" "C"]) ;; A little better...but not the same | |
;=> true | |
(get #{ "A" "B" "C"} "B") ;; more readable? | |
;=> "B" | |
(#{"A" "B" "C"} "B") ;; Idiomatic per Joy of Clojure | |
;=> "B" | |
;; See here for code from the book: | |
;; https://github.com/mjrusso/joy-of-clojure-examples/blob/master/src/joc/ch5.clj#L223 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment