Algorithms: Largest Sum Contiguous Subarray

Alexey Novakov published on

3 min, 480 words

Most of the algorithmic tasks are related to iterating over arrays of data. They often can be expressed as a function which takes some input and returns some single value or an array of values. For instance:

def maxSum(a: Array[Int]): Array[Int] = ???
Read More

Categories: scala

SBT Plugins

Alexey Novakov published on

12 min, 2210 words

SBT is a Scala Build Tool. It is written in Scala and can compile, build artefacts for Scala and Java projects. SBT is also the first build tool in the Scala eco-system and the most used one among Scala developers. I am using SBT already for many years and found the following useful plugins which I use in most of my projects:

Read More

Categories: 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