Skip to content

Instantly share code, notes, and snippets.

@rhysd
Last active November 19, 2016 17:02
Show Gist options
  • Save rhysd/4f32dc8706448a9ec54842968ac70a7f to your computer and use it in GitHub Desktop.
Save rhysd/4f32dc8706448a9ec54842968ac70a7f to your computer and use it in GitHub Desktop.
function! s:fold(list, init, pred) abort
let acc = a:init
for item in a:list
let acc = a:pred(acc, item)
endfor
return acc
endfunction
echo s:fold([1, 2, 3, 4, 5], 0, {acc, i -> acc + i})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment