Skip to content

Instantly share code, notes, and snippets.

View Synesso's full-sized avatar

Jem Mawson Synesso

View GitHub Profile
scala> val tuple = ("a string", 99, bigFlathead)
tuple: (java.lang.String, Int, Fish) = (a string,99,Fish(flathead,big))
scala> val (s, i, f) = tuple
s: java.lang.String = a string
i: Int = 99
f: Fish = Fish(flathead,big)
scala> val adjective = "sloppily"
adjective: java.lang.String = sloppily
scala> <fish><kiss how={adjective}><describe>{kiss(adjective)}</describe></kiss></fish>
res0: scala.xml.Elem = <fish><kiss how="sloppily"><describe>You sloppily kiss a big flathead</describe></kiss></fish>
case class Fish(species: String, size: String) {
val kiss: (String) => String = (adjective) => "You %s kiss a %s %s".format(adjective, size, species)
}
scala> val bigFlathead = Fish("flathead", "big")
bigFlathead: Fish = Fish(flathead,big)
scala> val kiss = bigFlathead.kiss
kiss: (String) => String = <function1>
case class Sandwich(bread: String = "wholemeal", filling: String = "tomato")
scala> Sandwich(filling = "salad")
Sandwich(wholemeal,salad)
case class Person(name: String, birthday: Date, languagesSpoken: List[String])
object Hello {
def world = "Bonjour"
}
scala> Hello.world
java.lang.String = Bonjour
scala> val fruit = List("apple", "banana", "lemon")
private List<String> fruit = new ArrayList<String>(Arrays.asList("apple", "banana", "lemon"));
scala> aString.to[tab]
toCharArray toLowerCase toString toUpperCase
System.out.println(_: String)
(String) => Unit
"some string".toUpperCase _
() => String
100 + (_: Int)
(Int) => Int
{i: Int => i > 500}
def debug(msg: String) {
// msg has already been resolved to a String
if (allowDebug) println(msg)
}
def debug(msg: => String) {
// msg is a function that will not be invoked if !allowDebug
if (allowDebug) println(msg)
}