Fork me on GitHub
#specter
<
2019-01-15
>
fmn00:01:41

How do you translate this vanilla clj function to a specter one?

(defn web-server-config
  [config]
  (let [{:keys [port] :as config} (:web-server config)
        port                      (if (pos-int? port) port 8080)]
    (assoc config :port port)))
I can easily got it working with this, but I'm just wondering if there's a better way to do it with specter:
(defn web-server-config
  [config]
  (->> config
       (sp/transform [:web-server :port] #(if (pos-int? %) % 8080))
       (sp/select-one [:web-server (sp/nil->val {})])))

nathanmarz05:01:15

@funyako.funyao156 you can do it in one line like this:

(select-any
  [:web-server
   (nil->val {})
   (transformed [:port (complement pos-int?)] (fn [_] 8000))
   ]
  config)

nathanmarz05:01:19

not a big difference