Lambda use with a foldLeft function

Report a typo

We have a vector of some Products:

case class Product(name: String, price: BigDecimal, inStock: Boolean)

val products: Vector[Product]

Calculate the total price of products in stock using a lambda function. Save the result to the totalPriceInStock value.

Sample Input 1:

Product(Apple,1.0,true)
Product(Banana,2.0,false)
Product(Orange,1.5,true)

Sample Output 1:

2.5
Write a program in Scala 3
val totalPriceInStock: BigDecimal = products.foldLeft(???) { ??? }

Create a free account to access the full topic