scala

Monads in Scala

Alexey Novakov published on

14 min, 2616 words

Once you start dig deeper into Scala and its suitability for functional programming, you meet Monads. In this blog post, we will explore Monads in Scala: their usage and usefulness.



Read More

Categories: scala

Tags: fp

Cats-Effect: Cancel Scala Process on Timeout

Alexey Novakov published on

4 min, 735 words



Sometimes Scala developer needs to call external program, which is running outside of the JVM. In this case, we use scala.sys.process package. Process package has bunch of functions to spin up new processes, consume their outputs and errors. Also, spawned process can be stopped. Usually, we run external programs for a short period of time to make some side-effect. Then, we analyse its exit code to apply some error handling logic in our main Scala program. It worth to say that process API is blocking execution thread, when we are waiting for its completion. To summarise, Scala developer wants to do the following:

Read More

Categories: scala

Scala FS2 - handle broken CSV lines

Alexey Novakov published on

6 min, 1104 words

Recently, I ran into a familiar situation by doing data processing, where I needed to deal with a fragmented data stream. Having fragments, I had to detect manually where exactly new line/message starts and where current line/message ends in the stream. As turned out, one can aggregate intermediate state of the fragmented stream using scan function.

Let us dig down into how scan function is working.



Read More

Categories: scala