Scala fold right and fold left
<p>I am trying to learn functional programming and Scala, so I'm reading the "Functional Programming in Scala" by Chiusano and Bjarnason. I' m having trouble understanding what fold left and fold right methods do in case of a list. I've looked around here but I haven't find something beginner friendly. So the code provided by the book is:</p>

<pre><code>def foldRight[A,B](as: List[A], z: B)(f: (A, B) =&gt; B): B = as match {
  case Nil =&gt; z
  case Cons(h, t) =&gt; f(h, foldRight(t, z)(f))
}

def foldLeft[A,B](l: List[A], z: B)(f: (B, A) =&gt; B): B = l match {
  case Nil =&gt; z
  case Cons(h,t) =&gt; foldLeft(t, f(z,h))(f)
}
</code></pre>

<p>Where Cons and Nil are:</p>

<pre><code>case class Cons[+A](head: A, tail: List[A]) extends List[A]
case object Nil extends List[Nothing]
</code></pre>

<p>So what do actually fold left and right do? Why are needed as "utility" methods? There are many other methods that use them and I have trouble to understand them as well, since I don't get those two.</p>