Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
;; Without helpers
(apply * (map inc (reduce + 0 [1 2 3 4 5])))
;; using ->>
(->> (reduce + 0 [1 2 3 4 5])
(map inc)
(apply *))
;; broken up using let
(let [reduced (reduce + 0 [1 2 3 4 5])
mapped (map inc reduced)]
(apply * mapped)
;; using as-> (best, in my opinion)
(as-> [1 2 3 4 5] num-vec
(reduce + 0 num-vec)
(map inc num-vec)
(apply * num-vec))
@sdegutis

This comment has been minimized.

Copy link

commented Sep 6, 2013

(->> [1 2 3 4 5]
     (reduce + 0)
     (map inc)
     (apply *))
@brandonbloom

This comment has been minimized.

Copy link

commented Sep 6, 2013

(let [num-vec [1 2 3 4 5]]
  (reduce + 0 num-vec)
  (map inc num-vec)
  (apply * num-vec))
@brandonbloom

This comment has been minimized.

Copy link

commented Sep 6, 2013

But yeah, clearly ->> wins

@cjfrisz

This comment has been minimized.

Copy link
Owner Author

commented Sep 6, 2013

Yeah, dude, that let don't work.

@danneu

This comment has been minimized.

Copy link

commented Sep 6, 2013

@brandonbloom, I guess you meant:

(let [num-vec [1 2 3 4 5]
      num-vec (reduce + 0 num-vec)
      num-vec (map inc num-vec)]
  (apply * num-vec)))

I never even knew about as-> until now. But it's nice in that it doesn't depend on arg order like -> and ->>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.