JVM Languages like Java and Scala have the ability to run concurrent code using the Thread class. Threads are notoriously complex and very error prone, so having a solid understanding of how they work is essential.

Let’s start with the Javadoc for Thread.sleep:

Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds

What are the implications of cease execution a.k.a blocking, what does it mean? is it bad? and if so can we achieve non-blocking sleep?

Image for post
Image for post

Overview

This post covers a lot of ground and hopefully, you will learn a lot of cool things.


Image for post
Image for post
Photo by John Schnobrich on Unsplash

I have been using ScalaCheck testing library for at least 2 years now. It allows you to take your unit tests to the next level.

Property-based testing

Here is our beloved User data type:

case class User(name: String, age: Int)

And a random User generator:

import org.scalacheck.{ Gen, Arbitrary }
import Arbitrary.arbitrary
implicit val randomUser…


Image for post
Image for post
Photo by Connor Jalbert on Unsplash

Scala has a very special streaming library called FS2 (Functional Streams for Scala). This library embodies all the advantages of functional programming (FP). By understanding its design goals you will get exposure to the core ideas that make FP so appealing.

FS2 has one central type: Stream[Effect,Output]

You might get from this type that it’s a Stream and that it emits values of type Output.

The obvious question here is what is Effect? What is the link between Effect and Output? And what advantages does FS2 have over other streaming libraries?

Overview

I will start by reviewing what problems FS2 solves…


Last week I spoke at Scalapeño about “Thinking Less With Scala”. The video has just been published and I’m excited to share with you.

The main message of the talk is that Functional Scala allow you to think less when you read and write code. It demonstrates that good Functions Signatures, Data and Functional Patterns keep your mental stack small.

Watch this talk if you’d like to get started with Functional Programming in Scala, or if you’re already doing some FP but want an insight into the benefits.

At the end of the talk you will have answers for the following questions:


In this post I’ll use code examples to explain a fundamental functional programming concept called parametricity. This concept is an essential step in convincing yourself that there is something more profound to functional programming that meets the eye.

Type and value parameters

def f[A](a: A, b: String): String = "hi"

a and b are value parameters, the one you use most of the time.

A is a type parameter, the caller will decide what it is when he calls the function:

scala> f("hello", "panda")
res0: String = hi
scala> f(2, "panda")
res1: String = hi
scala> f(List(1,2,3), "panda")
res2: String = hi

As you…


This very abstract syntax comes up all the time in Scala, I will try to give you an intuition of what it means and how to use it.

Overview

The goal of this post is to understand this syntax and why you would need it. In order to do so we will gradually climb the ladder of abstractions and answer the following questions :

What is a value ?

Values represent raw data. They have the…


If you have a background in Java like me you probably read Refactoring To Patterns.

It’s a very cool book about refactorings that shows you how to refactor Object Orientated code step by step and eventually reach full blown Gang of Four design patterns. It had a huge impact on me at the time. It left me with the feeling that code is alive and wants to be rearranged this way, and that patterns emerge naturally.

Fast forward 10 years, and I work in a very cool startup (Bigpanda) where we use Scala and Functional programming for our back end…

Daniel Sebban

Scala/Akka/Functional Developer https://twitter.com/dsebban

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store