Skip to content

Instantly share code, notes, and snippets.

@loosechainsaw
Created October 15, 2013 11:55
Show Gist options
  • Save loosechainsaw/6990429 to your computer and use it in GitHub Desktop.
Save loosechainsaw/6990429 to your computer and use it in GitHub Desktop.
Fold Left
def foldLeft[T](l: List[T], initial: T, f: (T,T) => T) : T = {
def loop(v: List[T], accum: T) : T = {
l match{
case Empty => accum
case Cons(head,tail) => loop(tail, f(head,accum))
}
}
loop(l,initial)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment