Created
May 19, 2018 15:24
-
-
Save carcigenicate/9b33a4d567378081c70e9ef7792452a6 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
(reduce (fn [sum n] | |
(println sum n) | |
(+ sum n)) | |
0 | |
[1 2 3 4 5]) | |
; Prints | |
0 1 | |
1 2 | |
3 3 | |
6 4 | |
10 5 | |
=> 15 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sum
is the accumulator, the running sum.n
is each element of the list. Until you get more comfortable with reductions, I'd usefn
instead of#()
for functions. It'll make more sense.