Scala
Installed Scala and followed this book:
https://docs.scala-lang.org/scala3/book/introduction.html
brew install scala@3
Install IntelliJ and plugin, follow these instructions:
https://docs.scala-lang.org/getting-started/install-scala.html
REPL
val vs var (immutable vs mutable)
val b: Byte = 1
val i: Int = 1
val l: Long = 1
val s: Short = 1
val d: Double = 2.0
val f: Float = 3.0
val x = 1_000L // val x: Long = 1000
val y = 2.2D // val y: Double = 2.2
val z = 3.3F // val z: Float = 3.3
When you need really large numbers, use the BigInt and BigDecimal types:
var a = BigInt(1_234_567_890_987_654_321L)
var b = BigDecimal(123_456.789)
String interpolation
val firstName = "John"
val mi = 'C'
val lastName = "Doe"
You can combine those variables in a string like this:
println(s"Name: $firstName $mi $lastName") // "Name: John C Doe"
To embed arbitrary expressions inside a string, enclose them in curly braces:
println(s"2 + 2 = ${2 + 2}") // prints "2 + 2 = 4"
val x = -1
println(s"x.abs = ${x.abs}") // prints "x.abs = 1"
Multiline strings
Multiline strings are created by including the string inside three double-quotes:
val quote = """The essence of Scala:
Fusion of functional and object-oriented
programming in a typed setting."""
for loops and expressions:
val fruits = List("apple", "banana", "lime", "orange")
val fruitLengths = for
f <- fruits
if f.length > 4
yield
// you can use multiple lines
// of code here
f.length
// fruitLengths: List[Int] = List(5, 6, 6)