This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-23
Channels
- # adventofcode (92)
- # beginners (12)
- # boot (3)
- # boot-dev (38)
- # cider (9)
- # clara (26)
- # cljs-dev (26)
- # cljsrn (3)
- # clojars (3)
- # clojure (48)
- # clojure-france (6)
- # clojure-greece (2)
- # clojure-spec (3)
- # clojurescript (7)
- # datomic (3)
- # fulcro (6)
- # hoplon (19)
- # jobs-discuss (1)
- # leiningen (4)
- # lumo (9)
- # off-topic (8)
- # onyx (43)
- # planck (10)
- # powderkeg (4)
- # precept (44)
- # re-frame (4)
- # shadow-cljs (4)
- # sql (13)
- # uncomplicate (1)
- # unrepl (3)
@noisesmith @scot-brown @flowthing @admay Thank you very much for your comments! I found this discussion very illuminating.
@sabbatical2017 My pleasure!
@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}] ??
here’s one way to do it:
user=> (def a [{:a 1 :b 1} {:a 2 :b 2} {:a 3 :b 3}])
#'user/a
user=> (def b [{:c 1} {:c 2} {:c 3}])
#'user/b
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.
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. https://github.com/amckinnell/Gilded-Rose-Rubyhttps://github.com/amckinnell/Gilded-Rose-Ruby. 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.