def foldLeft[A,B](as: List[A], b: B)(f: (B, A) => B): B = as match { case Nil => b case h :: t => foldLeft(t, f(b, h))(f) }