Skip to content

Instantly share code, notes, and snippets.

@deanwampler
Created February 26, 2021 21:15
Show Gist options
  • Save deanwampler/35ed4392fd7b84eeecaf904aafcc13ee to your computer and use it in GitHub Desktop.
Save deanwampler/35ed4392fd7b84eeecaf904aafcc13ee to your computer and use it in GitHub Desktop.
import Matrix.`*`
def `1 + 1 == 2 test` = assert(1+1 == 2) // Readable test names!
def contains(i: Int, seq: Seq[Int]): Boolean = seq match {
case Nil => false
case `i` +: _ => true // Must use back ticks, or i is just a new variable that shadows the method argument.
case _ +: tail => contains(i, tail)
}
contains(3, Seq(1,2,3)) // true
contains(3, Seq(1,2)) // false
...
java.util.Scanner.`match` // Call a Java method named like a Scala reserved word.
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment