Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@YurySolovyov
Created July 2, 2017 12:17
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YurySolovyov/834e9cd6258f36d6f333fd3d0806c238 to your computer and use it in GitHub Desktop.
Save YurySolovyov/834e9cd6258f36d6f333fd3d0806c238 to your computer and use it in GitHub Desktop.
class-names for ClojureScript
(defn class-names [& args]
(clojure.string/join " "
(mapv name
(reduce (fn [arr arg]
(cond
(or (string? arg)
(symbol? arg)
(keyword? arg)) (conj arr arg)
(vector? arg) (vec (concat arr arg))
(map? arg) (vec (concat arr
(reduce-kv (fn [map-arr key value]
(if (true? value)
(conj map-arr key)
map-arr)) [] arg)))
:else arr)) [] args))))
; (class-names "foo" "bar" :bax { :active true :seleced false })
; -> "foo bar bax active"
; (class-names "foo" "bar" nil)
; -> "foo bar"
; (class-names "foo" "bar" :bax { :active true :seleced false } 'nox { :more-classes-in-map true })
; -> "foo bar bax active nox more-classes-in-map"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment