This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-10-20
Channels
- # admin-announcements (2)
- # beginners (38)
- # boot (12)
- # business (2)
- # cbus (2)
- # cider (8)
- # cljs-dev (32)
- # clojure (154)
- # clojure-brasil (43)
- # clojure-czech (3)
- # clojure-dev (5)
- # clojure-germany (1)
- # clojure-japan (2)
- # clojure-nl (2)
- # clojure-poland (9)
- # clojure-russia (29)
- # clojure-sg (12)
- # clojurescript (147)
- # clojurex (22)
- # community-development (2)
- # cursive (8)
- # events (3)
- # ldnclj (30)
- # ldnproclodo (1)
- # leiningen (1)
- # luminus (34)
- # off-topic (6)
- # om (255)
- # re-frame (1)
- # reagent (22)
- # rum (2)
- # yada (1)
here’s what I came up with @roberto
(let [smallest (first (sort-by :total_size my-typle))]
(map #(if (= % smallest) (assoc % :label "smaller") (assoc % :label "larger"))
my-typle))
thanks I’m sure there’s a still tighter way
alternative:
(map
#(assoc %1 :label %2)
(sort-by :total_size my-typle)
["smaller" "larger"])
Or, perhaps better:
(map
merge
(sort-by :total_size my-typle)
[{:label "smaller"} {:label "larger"}])
i think the tuple must remain in its original order
yep - that’s a useful one
@roberto: Yeah, they go in as extra arguments to your mapping fn. So passing in two colls, you have to provide a fn with the signature (fn [item-from-coll-1 item-from-coll-2])
.
The Api I'm getting the data from doesn't specify if the first item is always the largest
Yeah, one of the items is supposed to be an audio recording, the other a video recording. Determining that based on the size
@roberto, @potetm, @jeremyraines, but here’s a somewhat nicer version:
(let [big (max-key my-tuple :total-size)]
(map #(assoc % :label (if (= big %) "larger" "smaller”)) my-tuple))
it’s the same as @jeremyraines, but uses max-key
instead of sorting the list, and moves the if
inside the assoc
you’re welcome!
https://github.com/pedestal/pedestal looks interesting too
http://purelyfunctional.tv has a great screen cast for getting started.
When writing a defmacro, how can you handle arguments regardless of whether they were passed as data literals or values?
For example the for macro works as I expect wrt foo :
(def foo [1 2 3])
(for [x foo] x) ;; => (1 2 3)