Tag: Scala
-
Immutability and Co/Contravariance
After a long long time… Immutability also Empowers Type Safety. There are many reasons to use immutable data structures and you may have heard many of them. For example, immutable data is safe to be shared across multiple threads etc. Apart from all of these awesome benefits, immutability helps us…
-
Building a Simple and Performant DSL in Scala
Scala provides different language constructs by which a wide variety of DSLs can be made. Implicits, operators as name of functions, macros, higher order functions etc. are examples of those constructs. However, building a DSL is not a trivial task especially when performance matters. In this blog post, I am…
-
Scala Streams: A Deeper Look
To start, let’s take a look at the following code: process function is just a chain of transformations on the given Traversable. Each of these transformations will create an intermediate traversable to be passed to the next transformation function. Given xs = Array(1, 2, 5), the manual tracing output would…
-
Scala Futures with Timeout
Scala Futures do not support built-in timeout unless you block on the future using scala.concurrent.Await as follows: The above code will timeout: java.util.concurrent.TimeoutException: Futures timed out after [1 second] at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:219) at scala.concurrent.impl.Promise$DefaultPromise.result(Promise.scala:223) at scala.concurrent.Await$anonfun$result$1.apply(package.scala:107) at scala.concurrent.BlockContext$DefaultBlockContext$.blockOn(BlockContext.scala:53) … Sometimes non-blocking external libraries are providing futures as their functions return type…