Skip to content

Instantly share code, notes, and snippets.

@Spirans
Created April 10, 2018 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Spirans/e9866af6439ef082232404d923083287 to your computer and use it in GitHub Desktop.
Save Spirans/e9866af6439ef082232404d923083287 to your computer and use it in GitHub Desktop.
scala> def sum(l: List[Int]): Int = { l.fold(0) (_ + _) }
sum: (l: List[Int])Int
scala> sum(List(1,2,3,4))
res21: Int = 10
scala> sum(List(1))
res22: Int = 1
scala> sum(List())
res23: Int = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment