winitzki / sofp

A free book: "The Science of Functional Programming"
GNU General Public License v2.0
1.41k stars 97 forks source link

Example 2.2.5.1 possible extension #85

Closed andreas-roehler closed 10 months ago

andreas-roehler commented 10 months ago

The solution of Example 2.2.5.1 employs builtin math.max. It might be useful, to display a more iconic form too, like

def foldleftMax(s: Seq[Int]): Int = s.foldLeft(Int.MinValue) { (x, y) => if (x > y) x else y } scala>foldleftMax(List(-1, -4, -6, -2)) res1: Int = -1

winitzki commented 10 months ago

Thank you, I will add this to the text.