Next version of Scala/FP book, coming soon alvin June 20, 2017 - 5:10am

Update 1: The next version of my book on Scala and functional programming will be released later this week.

Update 2: The price of the book will be increased to $25 on July 1, 2017. books alvin June 11, 2017 - 2:46pm

The people at have made their books on Scala and functional programming free (or “donationware,” if you prefer). I’ve found the Advanced Scala with Cats book to be particularly good, and well worth a donation.

(Full disclosure: I didn’t pay for the Advanced Scala book when I first downloaded it, then went back and tried to pay for it, but the Gumroad website wouldn’t let me do that.)

Just trying to be a reporter alvin June 11, 2017 - 1:35pm

After the 0.1.2 release of Learning Functional Programming in Scala, it occurs to me that I need to be more explicit about my goals for the book. Some people seem to think that I’m trying to “sell” functional programming. That’s not the case at all. I’m just trying to be a reporter and explain what I’ve learned about FP after reading dozens (hundreds?!) of articles and many books on FP, learning Haskell, trying to apply these techniques to my own code, etc. I’ll explain this further in the next release of the book.

Learning Functional Programming in Scala (pdf)

Table of Contents1 - What’s new2 - Buying the book3 - One more thing4 - Preview5 - Some time in the future ...

My new book, Learning Functional Programming in Scala, is now available as a PDF you can purchase for just $10 US. Details are listed below.

Back to top

What’s new

If you’ve been following along with me recently, the latest changes are:

How to Enable Filtering in a `for` Expression

Next, let’s see if we can use a filtering clause inside of a for expression with the Sequence code we have so far.

Trying to use a filtering expression

When I paste the current Sequence class and this code into the Scala REPL:

val ints = Sequence(1,2,3,4,5)

val res = for {
    i <- ints
    if i > 2
} yield i*2

I see the following error message:

How To Make Sequence Work as a Single Generator in a ‘for’ Expression

Getting Sequence to work as a generator in a simple for loop was cool, but does adding foreach let Sequence also work when I add yield? Let’s see.

When I paste this code into the REPL:

val ints = Sequence(1,2,3)

for {
    i <- ints
} yield i*2

I see this error message:

How to Make Sequence Work in a Simple ‘for’ Loop

So far I have this Sequence class:

case class Sequence[A](initialElems: A*) {

    private val elems = scala.collection.mutable.ArrayBuffer[A]()

    // initialize
    elems ++= initialElems


With that code I can create new Sequence instances like this:

val strings = Sequence("a", "b", "c")
val nums = Sequence(1, 2, 3, 4, 5)

Next, I’ll modify Sequence so I can use it as a generator in a for loop.