Warning: Undefined array key "HTTP_REFERER" in /home/u522501990/domains/makemeengr.com/public_html/wp-content/themes/generatepress/generatepress.theme#archive on line 43

Scala: short form of pattern matching that returns Boolean

This is exactly why I wrote these functions, which are apparently impressively obscure since nobody has mentioned them.

scala> import PartialFunction._
import PartialFunction._

scala> cond("abc") { case "def" => true }
res0: Boolean = false

scala> condOpt("abc") { case x if x.length == 3 => x + x }
res1: Option[java.lang.String] = Some(abcabc)

scala> condOpt("abc") { case x if x.length == 4 => x + x }
res2: Option[java.lang.String] = None

Leave a Comment

techhipbettruvabetnorabahisbahis forumutaraftarium24edusedusedusedueduseduedusedusedusedus