-
-
Save cjfrisz/7f3e118098bb7a472e62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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
commented
Sep 6, 2013
(let [num-vec [1 2 3 4 5]]
(reduce + 0 num-vec)
(map inc num-vec)
(apply * num-vec))
But yeah, clearly ->> wins
Yeah, dude, that let don't work.
@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