Free Scala and functional programming training video courses (2024)
Just a periodic reminder today that here’s a link to my free Scala and functional programming training video courses at LearnScala.dev.
Just a periodic reminder today that here’s a link to my free Scala and functional programming training video courses at LearnScala.dev.
As a quick note today, here’s a list of my currently-free books and online video courses about the Scala programming language and functional programming (as of October, 2024):
If you haven’t seen them yet, here’s a link to Alvin Alexander’s free Scala 3 and Functional Programming video courses. The functional programming course shown in this image was just released today, September, 8, 2024.
October, 2024, and my new free “Functional Programming Fundamentals with ZIO” video course is now available!
Functional Programming FAQ: What are the benefits of an Effect System, like ZIO?
I’m currently planning a video on “The benefits of an Effect System in computer programming” on my free Scala and functional programming videos website, but in case I don’t get around to making that video, here are the slides I have put together.
Also, if you’d like to see a video that is somewhat similar, here’s my popular “What is ZIO 2?” video on YouTube.
If you haven’t heard of Effects or an Effects System, I wrote about them a long time ago here. Also, in book, Effect-Oriented Programming, the authors describe them this way:
In this fast-paced video I show what the ZIO 2 library is in the fastest way I know how. I show the benefits of effects and effect systems, and specifically how ZIO is the new “Functional Programming, Simplified.”
This page provides a comprehensive overview of error-handling strategies in ZIO 2. My hope is that you can use this decision tree to determine good/best approaches for handling errors in your ZIO
effects. Each section includes a use case (question/answer), brief explanation, and ZIO 2 example.
As a brief note, I have ensured that the following examples compile, but I feel like I need to double-check some of my work.
I noticed that the ZIO 2 ZIO.fromOption
method returns Option[Nothing]
as its error type, so I asked my friend Claude about it, and got the following response, which I have cleaned up a little.
Scala FAQ: What is the Nothing
type in Scala, and how do I use it?
In Scala, the Nothing
type is called a bottom type, which means it is a sub-type of every other type in the Scala type system. It is also specifically a data type that has no instances.
In practical use, Nothing
is used to indicate that a computation or function will never produce a result normally, either because it throws an exception, enters an infinite loop, or encounters some other abnormal termination.
Visually, this is what the Nothing
type looks like in the Scala type hierarchy (image courtesy of this scala-lang.org page):
Some common use cases of Nothing
in Scala include:
As I work more with ZIO 2, I also find myself thinking a lot about the ZIO 2 mental model, by which I partially mean “a way of thinking about your code” and also “ZIO 2 best practices.”
Here are my initial notes. Also, I hope that most of this code is mine, but several snippets are from other sources that I don’t remember, including the official ZIO 2 docs.
Functional Programming, Simplified — currently 5-star rated on Gumroad.com, 4.5-star rated on Amazon, and one of the all-time best-selling books on functional programming — is currently on sale in three formats (prices shown in USD):
PDF Format |
Paperback Book |
Kindle eBook |
I recently watched the movie, The Ten Commandments, and when I saw Sephora, I thought, “She looks familiar.”
It turns out she’s played by Yvonne De Carlo. She’s the actress who’s portrayed on my Learn Scala 3 book cover, which is based on the 1950 movie, Buccaneer’s Girl, which she starred in. (Until this, I thought I only knew her as Lily Munster on The Munsters.)
And if you like the movie The Ten Commandments, I also wrote this blog post about The Ten Commandments and the 2024 Presidential Election.
I’m glad to report that my book, Learn Functional Programming The Fast Way, is five-star rated on Gumroad.com. And as I write this sentence on September 6, 2024, it’s also FREE!
Scala 3 FAQ: What are opaque types in Scala?
I previously wrote a little about Opaque Types in Scala 3, and today, as I’m working on a new video about opaque types, I thought I’d add some more information about them.
As a quick note to self, I wrote this Scala code as a way to (a) find the first element in a sequence, and then (b) return that element without traversing the rest of the sequence.
I initially thought about writing this code with a while
loop, for
loop, or for
expression — because I knew I needed a loop and a way to break out of a loop — but then I realized that an iterator would help me out here.
Also, please note that there is a potentially-better solution after this — the one that uses the “view.”
So without any further ado, here’s this solution:
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 20.3, “Scala best practice: Think "Expression-Oriented Programming".”
You’re used to writing statements in another programming language, and want to learn how to write expressions in Scala, and the benefits of the Expression-Oriented Programming (EOP) philosophy.
Because functional programming is like algebra, there are no null values or exceptions in FP code. But of course you can still have exceptions when you try to access servers that are down or files that are missing, so what can you do? This lesson demonstrates the techniques of functional error handling in Scala.
NOTE: This is a chapter from my book, Learn Scala 3 The Fast Way. Due to a mistake, this lesson was not included in the book.
When you write functions, things can go wrong. In other languages you might throw exceptions or return null values, but in Scala you don’t do those things. (Technically you can, but other people won’t be happy with your code.)
Instead what we do is work with error-handling data types. To demonstrate this I’ll create a function to convert a String
to an Int
.
If you like Scala 3 opaque types, check out Kit Langton’s Neotype project as a BIG improvement to opaque types. Neotype gets rid of the opaque types verbose boilerplate code, and offers many more improvements that you’ll like as you use this feature more often.
(Or, for more information about them, see my free “Opaque Types in Scala 3” training video.)