Skip to content

Instantly share code, notes, and snippets.

@iboss-ptk
Last active January 31, 2016 06:12
Show Gist options
  • Save iboss-ptk/c4a96664e165f36ddf8a to your computer and use it in GitHub Desktop.
Save iboss-ptk/c4a96664e165f36ddf8a to your computer and use it in GitHub Desktop.
val accumulatingList = numbers
.foldLeft(List[Int]())((acc, curr) =>
if(!acc.isEmpty) acc :+ (acc.last + curr) else acc :+ curr)
// => List(1, 3, 6, 10, 15)
def contains(numbers: List[Int], target: Int) =
numbers.foldLeft(false)((acc, curr) => if(curr == target) true else acc || false)
contains(numbers, 4) // => true
contains(numbers, 20) // => false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment