Skip to content

Instantly share code, notes, and snippets.

@selimslab selimslab/class.sc

Last active Jan 2, 2020
Embed
What would you like to do?
trait Bark {
def bark: String = "Woof"
}
trait Dog {
def breed: String
def color: String
}
class SaintBernard extends Dog with Bark {
val breed = "Saint Bernard"
val color = "brown"
}
case class Person(name: String, phoneNumber: String)
val kate = Person("Kate", "4567")
val sq: Int => Int = x => x*x
val s = Set(3,5,7)
s.map(sq).filter(_ > 10).reduce (_+_)
val m = Map("fork" -> "tenedor", "spoon" -> "cuchara", "knife" -> "cuchillo")
val a = Array(1, 2, 3, 5, 8, 13)
if (x == 11) println("yeah") else println("nay")
(5 to 1 by -1) foreach (println)
"hello world".length
"hello world".substring(2, 6) // llo
"hello world".replace("C", "3")
"hello world".take(5) // hello
"hello world".drop(5) // world
val n = 45
s"We have $n apples"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.