Created
October 15, 2013 11:55
-
-
Save loosechainsaw/6990429 to your computer and use it in GitHub Desktop.
Fold Left
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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