Fork me on GitHub

@noisesmith @scot-brown @flowthing @admay Thank you very much for your comments! I found this discussion very illuminating.


@noisesmith @scot-brown @flowthing @admay @alexmiller For the record, I have come up with a solution using datascript that I consider very easy to read and reflecting my intent very well: (datascript.core/q '[:find ?a (min ?b) :in [[?a ?b] ...]] x). This returns ([2 2] [0 0] [1 1]) as required (here, as before, I used x to denote [[0 0] [0 1] [1 1] [1 2] [1 3] [2 2]].) The only drawback is that the datascript query takes 47 microseconds to run, as opposed to the 5 microseconds in scot-brown's neat ->> suggestion, but it seems still plenty fast enough for me.


i have [{:a 1 😛 1} {:a 2 😛 2} {:a 3 😛 3}] and [{:c 1} {:c 2} {:c 3}] and i want [{:a 1 😛 1 :c 1} [{:a 2 😛 2 :c 2} [{:a 3 😛 3 :c 3}] ??


😛 refers to ": b"


@amit5881 use three backticks (`) to wrap blocks of code


here’s one way to do it:

user=> (def a [{:a 1 :b 1} {:a 2 :b 2} {:a 3 :b 3}])
user=> (def b [{:c 1} {:c 2} {:c 3}])
user=> (mapv merge a b)
[{:a 1 :b 1 :c 1} {:a 2 :b 2 :c 2} {:a 3 :b 3 :c 3}]


i’m doing a coding exercise where you have to refactor some intentionally (the writers knew better) code. The clojure version seems particuallry perverse, though i could imagine worse if you were trying to be hard to read. It really feels like someone would have to go out of there way to use so many atoms, for loops and do blocks though.


That sounds like a great way to learn. Do you have a link you can share?


i’m not sure i can actually, its a private repo. But I have seen this sort of thing before, the best example, and quite possible where the inspiration comes from, is the Gilded Rose by Sandi Metz. Not clojure, but the idea is the same.


I think a lot of people might find sandi’s approach to be simplistic, possible arguing that good abstractions can’t arise from simple refactors, but she makes a strong case that they can in 99 bottles. I would honestly be very interested to hear how other developers with different experiences took from that book.


Thanks for the link, I'll check it out.