Is there a more concise way of conditionally building up a list in Scala? Here's where I'm starting:
(j, k) match {
case (0, 0) => List()
case (j, 0) => List((c1, j))
case (0, k) => List((c2, k))
case (_, _) => List((c1, j), (c2, k))
}
In comparison, I could do this with a String:
"" + (if (j > 0) "j-part" else "") + (if (k > 0) "k-part" else "")
This works with the String +
operator and with ""
. But can a similar thing be done with ::
and lists?