0

In Scala I have the next command:

  lPServ <- Pservs.getAll(.....some logical condition.....)

each element of lPserv has a "price" and "quantity" fields. For this list, I need to get the total of adding each

         e.price * e.quantity

where e is element of lPServ. Any ideas?

Thx

Jose Cabrera Zuniga
  • 2,348
  • 3
  • 31
  • 56

1 Answers1

1

If Pservs is:

case class Pservs(price: Int, quantity: Double)

then:

( for { e <- Seq(Pservs(12, 3), Pservs(6, 3)) } yield e.price * e.quantity ).sum
Xavier Guihot
  • 54,987
  • 21
  • 291
  • 190