Skip to content

Commit 5a4d258

Browse files
author
Chris Myers
committed
Adding folding exercises
1 parent a70fdbc commit 5a4d258

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/main/scala/com/rea/higherorder/FoldingExercises.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ object FoldingExercises {
1010
* the accumulator of the next call.
1111
*
1212
*/
13-
def foldLeft[A, B](initialValue: B, list: List[A])(f: (B, A) => B): B = ???
13+
def foldLeft[A, B](initialValue: B, list: List[A])(f: (B, A) => B): B = {
14+
def fl(acc:B, l:List[A]) : B = l match {
15+
case Nil => acc
16+
case h :: t => fl(f(acc, h), t)
17+
}
18+
19+
fl(initialValue, list)
20+
}
1421

1522
}

0 commit comments

Comments
 (0)