This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-24
Channels
- # aleph (4)
- # beginners (93)
- # cider (7)
- # cljs-dev (16)
- # cljsrn (5)
- # clojure (192)
- # clojure-dusseldorf (3)
- # clojure-italy (14)
- # clojure-russia (16)
- # clojure-serbia (1)
- # clojure-spec (85)
- # clojure-taiwan (1)
- # clojure-uk (79)
- # clojurescript (188)
- # code-reviews (9)
- # core-async (2)
- # crypto (1)
- # cursive (26)
- # datomic (21)
- # heroku (1)
- # hoplon (3)
- # jobs (7)
- # jobs-discuss (20)
- # jobs-rus (13)
- # off-topic (77)
- # om (15)
- # onyx (23)
- # pedestal (94)
- # planck (11)
- # proton (10)
- # protorepl (1)
- # re-frame (16)
- # ring (22)
- # ring-swagger (9)
- # rum (2)
- # specter (18)
- # testing (2)
- # untangled (14)
- # vim (12)
- # yada (58)
how do you guys feel about 'pure' functions and annoying signatures?
(defn contains-rc-branch? [^SVNRepository repo ^String path]
(not= nil (get-directories repo (str path "/branches/RC"))))
(defn contains-trunk-folder? [^SVNRepository repo ^String path]
(not= nil (get-directories repo (str path "/trunk"))))
(defn get-projects [^SVNRepository repo ^String path]
(->> (get-all-directories repo path 3)
(filter (partial contains-rc-branch? repo))
(filter (partial contains-trunk-folder? repo))))
Passing in the SVN object means every functions need an extra arg and is getting passed around within the ns everywhere. Are free variables within a ns so bad?the alternative you are proposing is something like (def repo ...)
then leaving it out of all the functions. that is not a good way to write code if you want to test it or reuse it. namespaces are not classes, there is no method to create different "instances" of a namespace with different values for repo
yeah thats pretty much what I thought. I've just been noticing that a lot of my code ends up in anon fns or calls to partial which break the readability and hide the business logic.
especially around filter/reduce/map. which is supposed to be the bread and butter of FP's readability use case
(defn filter-successful-deploy [deploys]
(filter #(= "SUCCESS" (:deploymentState %)) deploys))
(defn get-environment [{env-name :name
id :id}]
(-> (call-until-success (str base "deploy/environment/" id "/results") 10)
:results
filter-successful-deploy
first
(assoc :env-name env-name)))
usually just wrap up the filter with a named fn and suddenly the business intent becomes pretty clear again