Closed andreas-roehler closed 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
def foldleftMax(s: Seq[Int]): Int = s.foldLeft(Int.MinValue) { (x, y) => if (x > y) x else y }
foldleftMax(List(-1, -4, -6, -2))
Thank you, I will add this to the text.
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