Back to Fpinscala

11.Answer

answerkey/datastructures/11.answer.md

latest216 B
Original Source
scala
def sumViaFoldLeft(l: List[Int]) = foldLeft(l, 0, _ + _)
def productViaFoldLeft(l: List[Double]) = foldLeft(l, 1.0, _ * _)

def lengthViaFoldLeft[A](l: List[A]): Int = foldLeft(l, 0, (acc,_) => acc + 1)