The reduce method takes an associative binary operator function as parameter and will use it to collapse elements from the collection. Unlike the fold method, reduce does not allow you to also specify an initial value.
defreduce[A1 >: A](op: (A1, A1) ⇒ A1): A1
demo
val donutPrices: Seq[Double] = Seq(1.5, 2.0, 2.5)// find the sum of elements using reduce function explicitlyval sum: Double = donutPrices.reduce(_ + _)val sum1: Double = donutPrices.reduce((a, b) => a + b)// find the cheapest donut using reduce functionval priceMin = donutPrices.reduce(_ min _)val donuts: Seq[String] = Seq("Plain Donut", "Strawberry Donut", "Glazed Donut")// concatenate the elements from the sequence using reduce functionval donutsConcat = donuts.reduce((left, right) => left +", "+ right)