Skip to content

Instantly share code, notes, and snippets.

@terazzo
Created December 27, 2011 08:16
Show Gist options
  • Save terazzo/1523010 to your computer and use it in GitHub Desktop.
Save terazzo/1523010 to your computer and use it in GitHub Desktop.
Kraepelin w/ foldLeft
def f(g:(Int,Int)=>Int,x:List[Int]) = x match {
case head::tail => tail.foldLeft((head,List[Int]())){(acc,i)=>(i,g(i,acc._1)::acc._2)}._2.reverse
case Nil => Nil
}
println(f({_+_},List(1,2,3,4,5)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment