-
The Scala API
-
A comparison of Java and Scala
- Scala Features with reference to Java
- A Scala Tutorial for Java Programmers
- Java 8 vs Scala
- Roundup: Scala for Java Refugees
- The busy Java developer's guide to Scala: Functional programming for the object oriented
- Scala vs. Groovy vs. Clojure
- Samples of Scala and Java code where Scala code looks simpler/has fewer lines?
- Scala: A Scalable Language
-
A discussion of val versus var
-
Write a game that will take a tic-tac-toe board with X, O, and blank characters and detect the winner or whether there is a tie or no winner yet. Use classes where appropriate.
-
Bonus problem: Let two players play tic-tac-toe.
- A discussion on how to use Scala files
Getting Started with Scala StackOverflow: Read entire file in Scala? StackOverflow: Load Scala file into interpreter to use functions?
- What makes a closure different from a code block Scala Gotcha: Blocks And Functions Functional Scala: Closures
- Use
foldLeft
to compute the total size of a list of strings.
foldLeft:
(0 /: words) { _ + _.size }
(0 /: words) { (sum, word) => sum + word.size }
words.foldLeft(0)( _ + _.size )
words.foldLeft(0) { (sum, word) => sum + word.size }
foldRight:
(words :\ 0) { _.size + _ }
(words :\ 0) { (word, sum) => word.size + sum }
words.foldRight(0)( _.size + _ )
words.foldRight(0) { (word, sum) => word.size + sum }
- Write a Censor trait with a method that will replace the curse words Shoot and Darn with Pucky and Beans alternatives. Use a map to store the curse words and their alternatives.
trait Censor {
val replacement = Map("Shoot" -> "Pucky", "Darn" -> "Bean")
def censor(text: String) = (replacement :\ text) {
case ((key, value), memo) => memo.replaceAll(key, value)
}
}
new Censor{}.censor("Shoot, Darn")
- Load the curse words and alternatives from a file.
val source = scala.io.Source.fromFile("censor.text")
val lines = source.mkString.split('\n')
val map = (lines :\ Map()) { (line, memo) =>
println(line)
val words = line.split(',')
memo + (words(0) -> words(1))
}
source.close
- For the sizer program, what would happen if you did not create a new actor for each link you wanted to follow? What would happen to the performance of the application?
- Take the sizer application and add a message to count the number of links on the page.
- Bonus problem: Make the sizer follow the links on a given page, and load them as well. For example, a sizer for “google.com” would compute the size for Google and all of the pages it links to.