object Hello extends App {
println("hello, world")
}
case class Greeting(name: String) {
def sayHello = "hello, " + name
}
object Hello extends App {
val greeting = Greeting("James")
println(greeting.sayHello)
}
Built-in Multi-Threading
import scala.concurrent._
import ExecutionContext.Implicits.global
def pause(msg: String, duration: Int) = {
println(s"pausing for $duration seconds")
Thread.sleep(1000 * duration)
println(s"paused for $duration seconds")
msg
}
val aa: Future[String] = future { pause("three", 3) }
val bb: Future[String] = future { pause("one", 1) }
val cc: Future[String] = future { pause("two", 2) }
println(Await.result(aa, duration.Duration.Inf))
println(Await.result(bb, duration.Duration.Inf))
println(Await.result(cc, duration.Duration.Inf))
for {
j <- 1 to 3
k <- j to 3
} yield k