This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-10
Channels
- # announcements (4)
- # asami (3)
- # babashka (49)
- # beginners (56)
- # chlorine-clover (42)
- # cider (13)
- # clara (3)
- # cljfx (14)
- # clojure (65)
- # clojure-australia (2)
- # clojure-dev (12)
- # clojure-europe (57)
- # clojure-italy (10)
- # clojure-nl (3)
- # clojure-spec (25)
- # clojure-uk (25)
- # clojuredesign-podcast (11)
- # clojurescript (78)
- # code-reviews (16)
- # community-development (3)
- # cursive (14)
- # datomic (16)
- # depstar (20)
- # emacs (3)
- # figwheel-main (2)
- # fulcro (33)
- # helix (16)
- # jackdaw (15)
- # kaocha (13)
- # leiningen (3)
- # malli (33)
- # reveal (10)
- # shadow-cljs (29)
- # spacemacs (10)
- # sql (13)
@heow sorry to miss your thread about let examples, but here's one from my recent code. I posted a short babashka script for downloading artifacts from CircleCI, and the artifacts-for
function has an example. The first let line fetches recent builds, but I don't know if I've found a build number that I want, so the artifact-urls
local variable is guarded by a when
call. https://gist.github.com/justone/87918a0ca5ab65575d94bc6a127aa48e
the artifact-urls
function:
(defn artifacts-for
[ci user project job-name]
(let [recent-builds (-> (recent-builds-url ci user project recent-build-count "completed")
(curl/get)
(parse-body-json))
recent-job-build-num (find-build-num-for recent-builds job-name)
artifact-urls (when recent-job-build-num
(-> (artifacts-url ci user project recent-job-build-num)
(curl/get)
(parse-body-json)))]
artifact-urls))
It could also be done with a some->>
, like this:
(defn artifacts-for
[ci user project job-name]
(let [recent-builds (-> (recent-builds-url ci user project recent-build-count "completed")
(curl/get)
(parse-body-json))
artifact-urls (some->> (find-build-num-for recent-builds job-name)
(artifacts-url ci user project)
(curl/get)
(parse-body-json))]
artifact-urls))
I know exactly how hard this is, I've written articles on functional programming without code and it's a challenge. :-) That the podcast has a really great job of it!
thanks, it's a tough line to walk, especially in our recent episodes where we focus on a single function
I just listen to the Let Tricks episode too 😃 cool. There is a very famous trick in other communities called "Let over Lambda" (there is still a book with the same name) which is using let and defining a function inside the let body. The idea is to create a lexical scope to the variables that are visible only by that function.
For example in this code we used this trick https://github.com/lsevero/abclj/blob/master/src/abclj/core.clj#L60
nice reading https://letoverlambda.com/index.cl/guest/chap2.html#:~:text=A%20closure%20is%20like%20an,can%20funcall%20in%20multiple%20ways.&text=This%20let%20over%20two%20lambdas,the%20same%20enclosing%20counter%20variable.. ( I need to warn about the style/kind of language used by the author... might be good to read https://letoverlambda.com/index.cl/clarifications too)