This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-15
Channels
- # announcements (5)
- # architecture (17)
- # aws (2)
- # bangalore-clj (1)
- # beginners (157)
- # boot (22)
- # boot-dev (2)
- # cider (64)
- # clara (2)
- # cljs-dev (3)
- # clojure (30)
- # clojure-art (2)
- # clojure-australia (1)
- # clojure-belgium (1)
- # clojure-denver (1)
- # clojure-dusseldorf (1)
- # clojure-europe (8)
- # clojure-finland (2)
- # clojure-italy (9)
- # clojure-nl (21)
- # clojure-spec (261)
- # clojure-switzerland (3)
- # clojure-uk (67)
- # clojurescript (57)
- # clojurewerkz (2)
- # cursive (3)
- # datomic (27)
- # emacs (12)
- # figwheel-main (2)
- # fulcro (48)
- # garden (67)
- # graphql (41)
- # jobs (8)
- # kaocha (8)
- # liberator (2)
- # lumo (1)
- # off-topic (19)
- # parinfer (9)
- # perun (4)
- # re-frame (50)
- # reagent (7)
- # remote-jobs (4)
- # ring-swagger (20)
- # rum (6)
- # shadow-cljs (170)
- # specter (3)
- # tools-deps (19)
- # vim (3)
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