Skip to content

Instantly share code, notes, and snippets.

@pcn
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save pcn/9182360 to your computer and use it in GitHub Desktop.

Select an option

Save pcn/9182360 to your computer and use it in GitHub Desktop.
what does -> do in clojure, when I want to update keys in a map and pass that down? Does it re-bind?
(def file-config-map {"channel-queue-size" "128",
"send-dir" "/tmp/foo/send",
"spool-dir" "/tmp/foo",
"file-rotation-period-ms" "1000",
"temp-dir" "/tmp/foo/temp",
"channel-timeout" "250",
"lineproto-port" "2003",
"target-list" "host-a,host-b,host-c,host-d"})
(defn parse-int [maybe-a-string]
(println "Trying the number " maybe-a-string)
(cond
(number? maybe-a-string) maybe-a-string
(nil? maybe-a-string) 0
:else (Integer/parseInt maybe-a-string)))
(defn fix-config-types
"All config types are read from disk as strings. When they're
used, we need them to be other things - so far numbers and lists.
Convert those keys we know need to be convered here. Note that this
currently doesn't allow for e.g. nested keys to be modified"
[config]
(-> config
(into (for [k [config-numbers]] [k (parse-int (config k))]))
(into (for [k [config-lists]] [k (clojure.string/split (config k) #"\s*,\s*")]))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment