partition
definition
def partition(p: (A) ⇒ Boolean): (Repr, Repr)demo
val donutNamesAndPrices: Seq[Any] = Seq("Plain Donut", 1.5, "Strawberry Donut", 2.0, "Glazed Donut", 2.5)
val namesAndPrices: (Seq[Any], Seq[Any]) = donutNamesAndPrices.partition {
case name: String => true
case price: Double => false
}
// access the donut prices sequence from namesAndPrices
val prices = namesAndPrices._2scala> val namesAndPrices: (Seq[Any], Seq[Any]) = donutNamesAndPrices.partition {
| case name: String => true
| case price: Double => false
| }
namesAndPrices: (Seq[Any], Seq[Any]) = (List(Plain Donut, Strawberry Donut, Glazed Donut),List(1.5, 2.0, 2.5))Last updated