Susan Potter
snippets: Created / Updated

Scala WTFs - moments of confusion in the Scala REPL

Small sample of Scala WTFs circa 2014 from the REPL (many taken from Paul Phillips talks on the Scala Collections library):

scala> List("a", "b", "c").toSet // the only reasonable line of code in here
res1: scala.collection.immutable.Set[String] = Set(a, b, c)

scala> List("a", "b", "c").toSet() // seen this when learning Scala first time. ROFL.
res2: Boolean = false

scala> List(1, 2) ::: List("a", "b") // it'd be funny if you didn't care.
res3: List[Any] = List(1, 2, a, b)

scala> List(1, 2) ::: List(3, 4.0) // sad panda
res4: List[AnyVal] = List(1, 2, 3.0, 4.0)

scala> List(1, 2, 3) contains "wtf?" // LMAO if it didn't hurt so much
res5: Boolean = false

scala> Double.MaxValue - Int.MaxValue == Double.MaxValue // I don't even …
res6: Boolean = true

scala> 555555555.round // :)
res0: Int = 555555584

If you enjoyed this content, please consider sharing via social media, following my accounts, or subscribing to the RSS feed.