This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Sandwich(bread: String = "wholemeal", filling: String = "tomato") | |
scala> Sandwich(filling = "salad") | |
Sandwich(wholemeal,salad) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Person(name: String, birthday: Date, languagesSpoken: List[String]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Hello { | |
def world = "Bonjour" | |
} | |
scala> Hello.world | |
java.lang.String = Bonjour |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> val fruit = List("apple", "banana", "lemon") | |
private List<String> fruit = new ArrayList<String>(Arrays.asList("apple", "banana", "lemon")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> aString.to[tab] | |
toCharArray toLowerCase toString toUpperCase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
System.out.println(_: String) | |
(String) => Unit | |
"some string".toUpperCase _ | |
() => String | |
100 + (_: Int) | |
(Int) => Int | |
{i: Int => i > 500} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |