Skip to content

Instantly share code, notes, and snippets.

@amonshiz
Created December 29, 2014 14:59
Show Gist options
  • Save amonshiz/6ee585dd4360d47baabd to your computer and use it in GitHub Desktop.
Save amonshiz/6ee585dd4360d47baabd to your computer and use it in GitHub Desktop.
foldl blog example
foldl (\acc x -> acc + x) 0 [1,2,3,4]
-- acc starts at 0, x starts as the first element of the list, so 1
-- 0 + 1 = 1 -> acc = 1, list = [2,3,4]
-- 1 + 2 = 3 -> acc = 3, list = [3,4]
-- 3 + 3 = 6 -> acc = 6, list = [4]
-- 6 + 4 = 10 -> acc = 10
-- therefore, this foldl results in a value of 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment