In Scala, unlike for example Haskell, a monad is just a concept — there is no superclass called Monad from which all monads inherit. A monad, basically, is any wrapper class which has a static method, unit (note: this is a popular name for the method; it’s not the Unit type), which accepts an element or a collection of elements and creates a monad with them inside, and which implements flatMap, enabling us to chain operations on the monad: We can create a monad from the original element, then flat-map this element to a monad of another type, flat-map…


Another idea you may already know but not associate with functional programming is that of an expression — as opposed to a statement. When writing code in the imperative style we build functions with statements. It’s how we order the program to do something: get data from here, modify it like that, save it there. From this point of view, the main purpose of a function is to modify the state of the program — that is, data outside the function itself. But in school, in mathematics, we also learned about functions, and they were not like that. Instead…


Or at least we will talk today about one of a few ways to do it. If you want to learn more about what is possible, and why it might be a good idea to consider an alternative to standard Android app development, please take a look a look at this article on Scala on Android or watch the associated conference talk.

But today we will talk about how to use GraalVM Native Image to compile Scala code to a file executable on Android, with Gluon libraries to access the Android platform beneath, and JavaFX for Graphical User Interface. Scala…


CODEX

The simple answer to how immutability helps with thread safety is — basically the same as with laziness. If data does not change it means that any number of threads can access it at any moment and they don’t mess with each other. But of course, the whole point of running a program is that we want to do something with data, not just read it. Data on which the program operates has to be mutated at some point in time, and so if the program runs on two or more threads, those threads can access the data and…


This is a blog post made from a transcription of a conference talk I gave at ScalaLove in February 2021. A link to the video will be added when the video from the conference is published.

For four years now I develop the Android client of Wire, an end-to-end encrypted messenger, written in Scala. In Android we deal a lot with events coming from many sources: the user, the backend, the Android OS itself. The code we write has to be very reactive — and it should also be concise and able…


Alexei Navalny
Alexei Navalny

We were friends for the last four years. We are no more. But it does not mean we can’t be again.

Yes, I saw those videos of Alexei Navalny from years ago, where he compares immigrants to a rotting tooth. I didn’t like it. I also know his views about Crimea and I don’t like it too. Navalny is definitely not a saint. He made mistakes in the past. He will probably make mistakes in the future.

… That is, he will, if he is ever free again.

See, nobody is a saint. We all make mistakes and we all…


I decided to write this article because I remember that back when I started to learn Scala around 2013–2014 the problem of how to return early from a loop actually happened to me a few times. I had a collection which I wanted to go through looking for the first entry which fulfilled some requirements, and then I wanted to jump out of the loop, taking that fitting result with me. At the time I was working in Java on a time-management webapp and situations as the one described above happened to me pretty often: There were long collections of…


One very cool thing about programming with functions is that data we work on does not have to be mutable so often. In theory — and languages like Haskell — it’s possible to never use mutability, but the alternative solutions can sometimes be pretty complicated or at least very weird-looking for an average coder. …


The unapply method

You can think of the unapply method as the opposite of apply... d’oh. Say, you have that sealed trait Cat and its companion object. There are two apply methods defined: they take the colour of the cat (or its lack of colour, so to say) and create a cat of the given colour (or without). Since right now the colour is the only property of the cat, then with a bit of stretch of the imagination you may think of it as wrapping the cat around the colour… okay, let’s change the example and talk about squares instead.

A…


Pattern matching is one of the most important features in Scala. It’s so important that I may risk saying that it’s not “a” feature of Scala, but the feature. It affects every other part of the programming language to the point where it’s difficult to talk about anything in Scala without it being mentioned or used in a code example. You have already seen it — the match/case statements, the partial functions, and the destructuring of instances of case classes. For this very reason, many things I’m going to talk about here you already know, so feel welcome to…

Maciek Gorywoda

Scala. Rust. Bicycles. Trying to mix kickboxing with aikido. Trying to be a better person too. Similar results in both cases. 🇪🇺 🇵🇱

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