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 {})])))
@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)
not a big difference