Last active
August 29, 2015 14:11
-
-
Save ThomasCrevoisier/f262df43937245e91187 to your computer and use it in GitHub Desktop.
Keyword to property conversion in ClojureScript
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
;;; ClojureScript example from David Nolen's talk "ClojureScript : Lisp's revenge" | |
;;; https://www.youtube.com/watch?v=MTawgp3SKy8 | |
(defn capitalize [s] | |
(str (.toUpperCase (aget s 0)) | |
(.substring s 1))) | |
(defn keyword->property [k] | |
(let [[x & xs] (-> (str k) (.substring 1) (.split "-"))] | |
(apply str x (map capitalize xs)))) | |
(keyword->property :border-radius) ;;; output : "borderRadius" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment