This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-06-16
Channels
- # ai (1)
- # announcements (3)
- # architecture (14)
- # aws (1)
- # babashka (8)
- # beginners (62)
- # biff (27)
- # calva (14)
- # clerk (6)
- # clj-kondo (6)
- # cljsjs (1)
- # clojure (59)
- # clojure-austin (1)
- # clojure-europe (15)
- # clojure-gamedev (5)
- # clojure-norway (246)
- # clojurescript (3)
- # community-development (5)
- # cursive (4)
- # data-science (6)
- # datomic (88)
- # events (1)
- # lambdaisland (1)
- # lsp (20)
- # matrix (1)
- # meander (6)
- # music (1)
- # off-topic (59)
- # pedestal (2)
- # releases (3)
- # shadow-cljs (90)
- # specter (6)
- # tools-build (5)
- # tools-deps (5)
- # xtdb (11)
Here comes another newbie question 😅
I often want to capture :out
from babashka.proces/sh
and sometimes parse it to JSON, so I made these helper functions:
(defn sh->out
[opts & args]
(-> (apply process/sh opts args)
:out))
(defn sh-out->json
[opts & args]
(-> (sh->out opts args)
(json/parse-string true)))
And I also have this function to run Git commands:
(defn run-git-command
[command path]
(-> (process/sh {:dir path} "git" command)
:out))
Example usage:
(->> (find-repo-paths (str (babashka.fs/home) (:local/repo-root-dir settings)))
(map (partial run-git-command "status")))
I just realized that run-git-command
does very little and can probably be removed in favor of using sh->out
directly.
But I can't figure out how to pass {:dir path}
into sh->out
(for its first parameter, opts
) via the threading macro:
(-> (find-repo-paths (str (babashka.fs/home) (:local/repo-root-dir settings)))
(map (partial sh->out {:dir ???} "git" "status")))
(->> (find-repo-paths (str (babashka.fs/home) (:local/repo-root-dir settings)))
(map #(sh->out {:dir %} "git" "status")))
should work?Oooh, I didn't consider using an anonymous function in there with %
. Clever. It works! Thanks!
And now I also better understand https://clojurians.slack.com/archives/C053AK3F9/p1686751979454239?thread_ts=1686751356.970239&cid=C053AK3F9 from @U04V15CAJ
another thing ive learnt over time is that whenever i feel a need to use partial, see if #(...)
solves it first. its a more general solution than partial
Thanks to help from others in the community, I'm slowly building up a mental inventory of "rules of thumb," like "`#(...)` is often preferable to partial
." They come with experience. Perhaps collecting such "rules of thumb" and sharing them somewhere would be helpful. Almost like "Clojure Proverbs" 😂
a lot of the ahas can also be found in: https://gist.github.com/reborg/dc8b0c96c397a56668905e2767fd697f
The closes thing I've seen to that is the book https://leanpub.com/elementsofclojure by @U066UJ2KE