Very cool everyone. This is exactly the kind of feedback I was hoping for. 
I'm going through Clojure for the Brave and I hadn't made it to the macros 
chapter yet. That single threading macro is pretty sweet!

Thanks everyone!

On Monday, December 14, 2020 at 11:00:02 AM UTC-6 brando...@gmail.com wrote:

> Hey James,
>
> Another small suggestion is you can just pass println to map, since it 
> takes 1 argument in your case.
>
> (map println (sort builds))
>
> But here, since you just want to perform side effects, maybe run! would 
> be a better function to use.
>
> (run! println (sort builds))
>
> This would cause it to return just one nil. Clojure is a functional 
> language, and every function returns a value. You'll see the return in 
> your REPL, but if the program is run in another way, such as packaged as a 
> jar, you would just see the print output.
>
> - Brandon
>
> On Mon, Dec 14, 2020 at 8:42 AM Justin Smith <noise...@gmail.com> wrote:
>
>> a small suggestion: you don't need to nest let inside let, a clause
>> can use previous clauses:
>>
>> (defn get-latest-build
>>   [pipeline]
>>   (let [response (fetch-pipeline pipeline)
>>         json (parse-string (:body response) true)
>>        [pipeline] (:pipelines json)]
>>   (:counter pipeline))))
>>
>> also consider using get-in:
>>
>> (defn get-latest-build
>>   [pipeline]
>>   (let [response (fetch-pipeline pipeline)
>>         json (parse-string (:body response) true)]
>>    (get-in json [:pipelines 0 :counter])))
>>
>> finally, this can now be simplified into a single threading macro:
>>
>> (defn get-latest-build
>>   [pipeline]
>>   (-> (fetch-pipeline pipeline)
>>       (:body)
>>       (parse-string true)
>>       (get-in [:pipelines 0 :counter])))
>>
>> On Mon, Dec 14, 2020 at 7:18 AM James Lorenzen <jamesl...@gmail.com> 
>> wrote:
>> >
>> > Hello all,
>> > This is my first Clojure program and I was hoping to get some advice on 
>> it since I don't know any experienced Clojure devs. I'm using it locally to 
>> print the latest build numbers for a list of projects.
>> >
>> > ```
>> > (ns jlorenzen.core
>> >   (:gen-class)
>> >   (:require [clj-http.client :as client])
>> >   (:require [cheshire.core :refer :all]))
>> >
>> > (defn fetch-pipeline
>> > [pipeline]
>> > (client/get (str "https://example.com/go/api/pipelines/"; pipeline 
>> "/history")
>> > {:basic-auth "username:password"}))
>> >
>> > (defn get-latest-build
>> > [pipeline]
>> > (let [response (fetch-pipeline pipeline)
>> > json (parse-string (:body response) true)]
>> > (let [[pipeline] (:pipelines json)]
>> > (:counter pipeline))))
>> >
>> > (def core-projects #{"projectA"
>> > "projectB"
>> > "projectC"
>> > "projectD"})
>> >
>> > (defn print-builds
>> > ([]
>> > (print-builds core-projects))
>> > ([projects]
>> > (let [builds (pmap #(str % " " (get-latest-build %)) projects)]
>> > (map #(println %) (sort builds)))))
>> > ```
>> >
>> > This will output the following:
>> > ```
>> > projectA 156
>> > projectB 205
>> > projectC 29
>> > projectD 123
>> > (nil nil nil nil)
>> > ```
>> >
>> > A few questions:
>> >
>> > How can this program be improved?
>> > How idiomatic is it?
>> > How can I prevent it from returning the nils at the end? I know this is 
>> returning nil for each map'd item; I just don't know the best way to 
>> prevent that.
>> >
>> > Thanks,
>> > James Lorenzen
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "Clojure" group.
>> > To post to this group, send email to clo...@googlegroups.com
>> > Note that posts from new members are moderated - please be patient with 
>> your first post.
>> > To unsubscribe from this group, send email to
>> > clojure+u...@googlegroups.com
>> > For more options, visit this group at
>> > http://groups.google.com/group/clojure?hl=en
>> > ---
>> > You received this message because you are subscribed to the Google 
>> Groups "Clojure" group.
>> > To unsubscribe from this group and stop receiving emails from it, send 
>> an email to clojure+u...@googlegroups.com.
>> > To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/clojure/ccb868e0-7e0c-46df-80fc-712f718314e3n%40googlegroups.com
>> .
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/clojure/CAGokn9L65oxePmfJqEDNvyhS9XL-JFjDbQAfk5zdiRctXS_-bQ%40mail.gmail.com
>> .
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/5a275c35-497e-4f68-94e5-a8a05d686dcdn%40googlegroups.com.

Reply via email to