Skip to content

Instantly share code, notes, and snippets.

@missingfaktor
Created November 14, 2011 11:47
Show Gist options
  • Select an option

  • Save missingfaktor/1363790 to your computer and use it in GitHub Desktop.

Select an option

Save missingfaktor/1363790 to your computer and use it in GitHub Desktop.
"cond" for Scala
def cond[A, B](value: A)(cases: (A => Boolean, B)*): B = {
cases.collectFirst({ case (c, v) if c(value) => v }).getOrElse(sys.error("Match error!"))
}
def otherwise[A] = Function.const(true)(_: A)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment