Scala Good to Know Before Start

Spread the love

Concurrency: Akka − It uses the actor model to simplify concurrent and distributed programming.

Futures and Promises: For Async functions and callbacks.

Parallel Collections: Thread safe collections

ScalaSTM: Lightweight software transactional memory (STM)

Pattern Matching: Same as .Net core switch expression but ‘match’ instead of ‘switch’ keyword

case class: Same as .Net sealed classes with only get and init props, or better records.

HOCs: If you know React then you know what they are. In .Net these are equivalent to delegates as parameters.

Traits: Interfaces in Scala. Equivalent to the latest .Net core interfaces functionality e.g. default concrete implementation. But traits can have fields too.

Immutability: An object is created; it cannot be changed.

Error handling:

Functional way

import scala.util.{Try, Success, Failure}

val result = Try(10 / 0)
result match {
   case Success(value) => println(s"Success: $value")
   case Failure(exception) => println(s"Failure: ${exception.getMessage}")
}

Either and Option

try, catch, finally

Implicit parameters: Implicit parameter which is marked as implicit doesn’t need to passed to function explicitly.

Implicit Conversion: Kind of as it is done in JS

Scripting: Scala can be used as it is with ‘.scala’ extension as it is PHP or JS. And can be compiled to bytecode.