Fork me on GitHub
#beginners
<
2015-10-20
>
jeremyraines00:10:02

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))

roberto00:10:16

Oh, nice. Mines was very imperative. Yours is much nicer

roberto00:10:07

It didn't occur to me to sort by :total_size

jeremyraines00:10:16

thanks simple_smile I’m sure there’s a still tighter way

potetm00:10:11

alternative:

(map
  #(assoc %1 :label %2)
  (sort-by :total_size my-typle)
  ["smaller" "larger"])

potetm00:10:46

Or, perhaps better:

(map
  merge
  (sort-by :total_size my-typle)
  [{:label "smaller"} {:label "larger"}])

jeremyraines00:10:09

i think the tuple must remain in its original order

roberto00:10:45

Oh, didn't know map could take two colts

jeremyraines00:10:07

yep - that’s a useful one

potetm00:10:58

@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]).

potetm00:10:01

Yeah, if the original order matters things get a little ugly.

roberto00:10:54

It doesn't matter in this case, luckily

roberto00:10:28

The Api I'm getting the data from doesn't specify if the first item is always the largest

roberto00:10:45

So I'm just covering my butt

potetm00:10:40

Never a bad idea.

roberto00:10:37

Yeah, one of the items is supposed to be an audio recording, the other a video recording. Determining that based on the size

isaac_cambron17:10:34

@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))

isaac_cambron17:10:51

it’s the same as @jeremyraines, but uses max-key instead of sorting the list, and moves the if inside the assoc

roberto17:10:19

it is the first time I’ve seen an application for max-key

isaac_cambron17:10:19

you’re welcome!

chadhs21:10:55

any recommendations on a good place to start building a basic web project?

roberto21:10:16

what do you mean? Good tutorial/resources for building web apps?

chadhs21:10:30

^ yes, exactly

chadhs21:10:40

i suppose my question was a tad vague, thanks

roberto21:10:07

I’ve never used it, but it looks like something good to start with.

chadhs21:10:36

ive looked at that a bit before, it does look like a nice tutorial / set of libraries

jjw21:10:02

http://purelyfunctional.tv has a great screen cast for getting started.

jfntn21:10:21

When writing a defmacro, how can you handle arguments regardless of whether they were passed as data literals or values?

jfntn22:10:01

For example the for macro works as I expect wrt foo :

(def foo [1 2 3])
(for [x foo] x) ;; => (1 2 3)

jfntn22:10:32

But in my own macro, unquoting the argument when it’s passed as foo like above would give me a Don't know how to create ISeq from: clojure.lang.Symbol exception

jfntn22:10:55

Works fine with the [1 2 3] literal however...