Last active
January 26, 2019 11:00
-
-
Save serioga/a9611d53703198180ba5a523730fc81f to your computer and use it in GitHub Desktop.
Matching without `match`.
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
(ns clojure-benchmarks.qwe | |
"To match or not to match. | |
https://t.me/clojure_ru/77518 | |
канаки, [25.01.19 19:57] | |
ну простой пример, когда нужно по разному хендлить [:qwe 0] и [:qwe n] | |
конечно это все можно и просто ификами написать, но это лишняя вложенностт") | |
(set! *warn-on-reflection* true) | |
(defn qwe | |
"extractor" | |
[[k v]] | |
(when (= k :qwe) v)) | |
(defn match-qwe | |
"matcher" | |
[q] | |
(case (qwe q) | |
0 "zero qwe" | |
1 "qwe one" | |
nil "not qwe" | |
"unhandled qwe")) | |
(comment | |
(qwe [:qwe 0]) | |
(qwe [:qwe 1]) | |
(match-qwe [:qwe 0]) | |
(match-qwe [:qwe 1]) | |
(match-qwe [:qwe 2]) | |
(match-qwe [:a 0])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment