Learn Functional Programming The Fast Way!, full paperback cover
If you’re interested in this sort of thing, this is the full paperback cover of my new book, Learn Functional Programming The Fast Way!, as seen in Amazon’s previewer.
If you’re interested in this sort of thing, this is the full paperback cover of my new book, Learn Functional Programming The Fast Way!, as seen in Amazon’s previewer.
March, 2023: This book was previously named, Learn Functional Programming Without Fear, but I have renamed it to Learn Functional Programming The Fast Way!. I think this name is more reflective of the ZIO and Cats Effect libraries being easier to learn than ever before (without having to know category theory), and the name is also consistent with my other book, Learn Scala 3 The Fast Way!.
February, 2023: Learn Functional Programming Without Fear is now one of my best-selling books on Gumroad.com (see the link below).
November, 2022: My new book, Learn Functional Programming Without Fear, is currently an Amazon Java and functional programming #1 new release. The book is now available in three formats:
PDF Format |
Paperback |
Kindle |
Cool, I’m glad to report that Learn Functional Programming The Fast Way! is an Amazon #1 New Release.
This weekend I just released the shiny new paperback version of Learn Functional Programming The Fast Way!. And for the first 48 hours — until roughly the end of March 28, 2023 — you can buy it for half-price, here on Amazon.com.
When coming to Scala from Java, the syntax for accessing a character at a position in a Scala String
is an interesting thing. You could use the Java charAt
method:
scala> "hello".charAt(0) res0: Char = h
However, the preferred (proper) approach to access a character in a String
is to use Scala’s Array
notation:
[toc]
This page contains a collection of over 100 Scala String
examples, including string functions, format specifiers, and more. I don’t provide too many details about how things work in these examples; this is mostly just a collection of examples that can be used as a Scala String
reference page or cheat sheet. (I do show the output of most examples.)
If you want to get a value out of a Scala Option
type, there are a few ways to do it. I’ll show those approaches in this article, and then discuss the approach of using the fold
method on an Option
(which I’ve seen discussed recently).
As a first look at getting values out of an Option
, a common way to extract the value out of a Scala Option
is with a match
expression:
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
.
I decided to rename my book, Learn Functional Programming Without Fear to Learn Functional Programming The Fast Way! because (a) I think it’s more reflective of today’s world, and (b) it’s consistent with my other book, Learn Scala 3 The Fast Way!.
You can currently find the PDF version of Learn Functional Programming The Fast Way! at this Gumroad.com URL.
I’m currently updating my best-selling book, Functional Programming, Simplified, to cover Scala 3 and other technologies like ZIO and Cats Effect, and when that’s done, this will be the landing page for that book.
Until then, you can find the PDF for the new book that I’m creating here:
And you can find the Scala 2 version of the book here:
I’ll update this page as I have more information.
When I was writing my new functional programming book — Learn Functional Programming Without Fear — a few alternate titles for the book were:
That’s because I found out — almost by accident — that the fastest way for object-oriented programming (OOP) developers to learn functional programming (FP) goes like this:
Some of the computer programming books on the right side of this image are amazing, and I would never discourage anyone from reading the great ones.
But if you’re an object-oriented programming (OOP) developer who wants to start understanding functional programming (FP) over a weekend or a few nights of reading, that’s the goal of the new little book on the left: Learn Functional Programming Without Fear. It takes you from Java/OOP to functional programming in the simplest possible step-by-step learning process.
I taught Java and OOP for many years, and have used other OOP languages like Kotlin, Python, and Flutter/Dart, so I understand both OOP and FP, and I think that helped to make this a simple book for learning FP.
I also wrote the FP book in the middle — Functional Programming, Simplified — and it’s about three times larger than the little book on the left. I based it on most of the FP books on the right, and it goes into many details that the book on the left doesn’t go into. It’s big, but it’s still easier than reading all the books on the right.
I’ve been slowly working on a series of new Scala programming books, and today I’m proud to announce the first of these:
Starting today you can buy the PDF version of Learn Scala 3 The Fast Way! for just ten dollars — $10 (USD) — at this Gumroad.com URL.
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 functional programmers use the words effects and effectful, but it can be hard to find a definition of what these terms mean.
A first step in the process of understanding effects is to say that they’re related to monads, so you have to know just a wee bit about monads to understand effects.
But fear not, this is surprisingly simple. As I write in my book, Functional Programming, Simplified, a slight simplification is to say that in Scala, a monad is any class that implements the map
and flatMap
methods. Because of the way Scala for-expressions work, implementing those two methods lets instances of that class be chained together in for-expressions (i.e., for
/yield
expressions).
My book, Functional Programming, Simplified — 4.5-star rated on Amazon, their 6th-best selling book on functional programming, and 5-star rated on Gumroad.com — is currently on sale in three formats (prices shown in USD):
PDF Format |
Paperback Book |
Kindle eBook |
I hope that my new book, Learn Functional Programming Without Fear, is the easiest and simplest way to learn functional programming (FP). I didn’t initially intend for it to be an FP book, but as I was writing about pure functions, immutable (algebraic) variables, immutable data structures, and functional error-handling, I realized that these were the first four essential stepping stones to help you transition from OOP to FP, and to Scala/FP libraries like ZIO and Cats Effect.
Initially I was planning to write a book titled something like “Thinking with Types” or “Solving Problems with Pure Functions,” but once I realized where it was going, I decided to create a new functional programming book that’s much shorted than my own, Functional Programming, Simplified book.
At the time of this writing there aren’t many examples of the Scala Exception
object allCatch
method to be found, so I thought I’d share some examples here.
In each example I first show the "success" case, and then show the "failure" case. Other than that, I won’t explain these, but hopefully seeing them in the REPL will be enough to get you pointed in the right direction:
I originally wrote a long introduction to this tutorial about how to work with the Scala Option/Some/None classes, but I decided to keep that introduction for a future article. For this article I’ll just say:
null
valuesOption
, Some
, and None
match
expressions to handle Option
valuesmatch
expressions tend to be verbosemap
, filter
, fold
, and many others are the cure for that verbosityGiven that background, the purpose of this article is to show how to use HOFs rather than match
expressions when working with Option
values.
Scala List FAQ: Can you share some Scala List
class examples?
The Scala List class may be the most commonly used data structure in Scala applications. Therefore, it's very helpful to know how create lists, merge lists, select items from lists, operate on each element in a list, and so on.
In this tutorial, I'll share examples of the most common List
operations (methods).
This is a “cheat sheet” for the Scala 3 language. I initially wrote it for my book Learn Functional Programming Without Fear, but I thought I’d share it here as well.
If you want to see many more details about Scala 3, see: