This document discusses Scala programming language trends. It provides examples of popular Scala features like pattern matching, futures/asynchronous programming, and the Try monad. It also briefly mentions that Scala is open source and lists some of the highest paying tech jobs in the US.
7. 5.
.
// - .
val a : String = "world"
val b = "hello"
//
val str = "hello world"
val WithHello = "hello (.*)".r
str match {
case WithHello(next) => println(next)
}
.
9. 7.threadpoolhell
Scala async .
// Asynchronous computations that yield futures are created with the Future call
val s = "Hello"
val f: Future[String] = Future {
s + " future!"
}
f onSuccess {
case msg => println(msg)
}
12. 10. - Try[T]
import scala.util.{Failure, Success, Try}
val success1: Try[String] = Success("success-1")
val success2: Try[String] = Success("success-2")
val fail: Try[String] = Failure(new IllegalStateException("Error"))
val result1 = for {
a <- success1
b <- fail
c <- success2
} yield c
// result1: scala.util.Try[String] = Failure(java.lang.IllegalStateException: Some Error)
val result2 = for {
a <- fail
b <- success1
c <- success2
} yield c
// result2: scala.util.Try[String] = Failure(java.lang.IllegalStateException: Some Error)