Tutorials about the Scala programming language.

How to drop the first matching element in a Scala sequence

Summary: This blog post shows one way to drop/filter the first matching element from a Scala sequence (Seq, List, Vector, Array, etc.). I don’t claim that the algorithm is efficient, but it does work.


While creating some Scala test code earlier today I had an immutable list of toppings for a pizza, and I got into a situation where I wanted to remove the first instance of a topping.

What is a monad in Scala? alvin August 15, 2019 - 11:07am

I started to write about what a monad is in Scala, but then I realized I’ve already done that in several places, including my tutorial, What do effect and effectful mean in functional programming. Therefore, I encourage you to read that article for more details, but as a brief introduction, here’s part of what I wrote there:

Mutable state is fine but ... alvin August 14, 2019 - 7:19am

“Mutable state is fine but needs to be contained and non-observable.” A quote from Jonas Bonér, which I saw in this tweet.

A “Minority Report” Monte Carlo simulation in Scala alvin August 13, 2019 - 6:47pm

This article shares the source code for a Monte Carlo simulation that I wrote in Scala. It was inspired by the movie Minority Report, as well as my own experience.


For the purposes of this simulation, imagine that you have three people that are each “right” roughly 80% of the time. For instance, if they take a test with 100 questions, each of the three individuals will get 80 of the questions right, although they may not get the same questions right or wrong. Given these three people, my question to several statisticians was, “If two of the people have the same answer to a given question, what are the odds that they are correct? Furthermore, if all three of them give the same answer to a question, what are the odds that they are right?”

Scala: What do “effect” and “effectful” mean in functional programming?

When you get started with functional programming (FP) a common question you’ll have is, “What is an effect in functional programming?” You’ll hear advanced FPers use the words effects and effectful, but it can be hard to find a definition of what these terms mean.

A Scala “functional programming style” To-Do List application written with Cats alvin August 11, 2019 - 3:56pm

Back when I was writing Functional Programming, Simplified I started to write a little Scala/FP “To-Do List” application that you can run from the command line, based on a similar application in the Learn You A Haskell For Great Good book. For reasons I don’t remember, I decided not to include it in the book, and forgot about it until I started using GraalVM (“Graal”) recently.

Links about the Scala 2.13 collections classes alvin August 11, 2019 - 9:15am

Related to some work/research I’m currently doing I thought I’d share these links about the Scala 2.13 collections classes:

This older link is also good:

The Science of Functional Programming (book) alvin August 10, 2019 - 10:41am

I haven’t read this yet, but here’s a link to an electronic version of a free book titled, The Science of Functional Programming. Who knows, it may one day have an impact on my book, Functional Programming, Simplified.