specter

Latest version: 1.1.3
fmn 2019-01-15T00:20:41.034900Z

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 {})])))

nathanmarz 2019-01-15T05:26:15.035400Z

@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)

nathanmarz 2019-01-15T05:26:19.035600Z

not a big difference