Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save carcigenicate/9b33a4d567378081c70e9ef7792452a6 to your computer and use it in GitHub Desktop.
Save carcigenicate/9b33a4d567378081c70e9ef7792452a6 to your computer and use it in GitHub Desktop.
(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
@carcigenicate
Copy link
Author

carcigenicate commented May 19, 2018

sum is the accumulator, the running sum. n is each element of the list. Until you get more comfortable with reductions, I'd use fn instead of #() for functions. It'll make more sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment