Back to Fpinscala

04.Answer

answerkey/laziness/04.answer.md

latest219 B
Original Source
scala
/* 
Since `&&` is non-strict in its second argument, this terminates the traversal as soon as a nonmatching element is found. 
*/
def forAll(p: A => Boolean): Boolean =
  foldRight(true)((a,b) => p(a) && b)