Skip to content

Instantly share code, notes, and snippets.

@noahlz
Created January 7, 2012 02:37
Show Gist options
  • Save noahlz/1573558 to your computer and use it in GitHub Desktop.
Save noahlz/1573558 to your computer and use it in GitHub Desktop.
idomatic search using persistent set in Clojure
(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