Scala, Java, Unix, MacOS tutorials (page 1)

Knowing of my interest in Zen, a friend of mine sent me this photo of a letter from Albert Einstein to a parent grieving after the loss of a child:

Albert Einstein, Zen Master

If you know something about Zen, you know that Einstein is writing about the “oneness” of the universe. Zen tries to teach us about this through techniques like Zen Meditation (zazen), and the concept of all things being interdependent.

Probably the most important scene in the movie, I.Q. :)

When was the last time you went ‘Wahoo’?

“I think you’re the kindest, sweetest, prettiest person I’ve ever met in my life. I’ve never seen anyone that’s nicer to people than you are. The first time I saw you ... something happened to me. I never told you but ... I knew that I wanted to hold you as hard as I could. I don’t deserve someone like you. But if I ever could, I swear I would love you for the rest of my life.”

~ from the movie, Groundhog Day

Thanks to Scala being both an object-oriented programming language and a functional programming language, here on the last day of August, 2021, the Scala Cookbook (for Scala 3) is the #1 new release in both the OOP and FP categories.

UPDATE: The book is still #1 in both categories on September 7, 2021 — one month after the Kindle release.

(In the image shown, the Amazon OOP category is on the left, and the FP category is on the right.)

Scala Cookbook: #1 new release in OOP and FP

October 11, 2011: After moving from Alaska to Colorado I spent about ten days trying to decide to live, and was staying in two hotels, one on the south side of Denver (in the Denver Tech Center area) and another on the north side. On this day I made the decision to live northwest of Denver and east of Boulder, and moved into my first apartment in Broomfield, and made this post on Facebook:

“Day one in the new apartment, slept on the floor, and there’s nothing to eat. Planning skills are questionable. But the fireplace is nice.”

Drowning in the Cooler of Love,
Where everyone,
Would love to drown.

~ an adaptation of a Stevie Nicks song

The Cooler of Love, Longmont, Colorado

My 700+ page book, Functional Programming, Simplified — 4.5-star rated on Amazon, their 6th-best selling book on functional programming, and 5-star rated on — is currently on sale in three formats (prices shown in USD):

PDF Format
$15 (sale!) on

PDF version of Functional Programming, Simplified

Paperback Book
Now $34.99 on Amazon

Print version of Functional Programming, Simplified

Kindle eBook
$14.99 on Amazon

Kindle version of Functional Programming, Simplified

We’ve had a lot of beautiful sunsets around here lately. Hard to believe that just about four days ago we had our first snow of the season.

Sunset in Boulder, Colorado (October 7, 2013)

Look mummy, there’s an aeroplane up in the sky. :)

It’s that time again in Colorado, late September leading into October leads to a lot of balloons in the sky.

Look mummy, there’s an aeroplane up in the sky

In the third line of Alanis Morissette’s song, Thank You, she sings, “How about them transparent dangling carrots?” In this article I’ll take a little look at what that line means.

A song about enlightenment

Ms. Morissette’s entire song is about gaining enlightenment, and from that perspective, a transparent dangling carrot is anything that leads you to take a path of pursuing or gaining enlightenment. In the song she mentions things like terror, disillusionment, frailty, consequence (karma), and silence; each of these can be considered motivational “carrots” that are capable of pulling a person down a path where they want to seek enlightenment.

As a brief personal note, I just remembered that back during 2014-2017 when I went unconscious seven times — a process known as syncope, and pronounced sync-oh-pee — I would later find out that the reason I went unconscious is because I didn’t feel the initial symptoms of MCAS. Those initial symptoms were suppressed because I was taking a statin.

So while I was taking a statin I would feel sick, like I’d been poisoned, and then go unconscious in a process that took 2-15 minutes. But on September 1, 2016, I stopped taking the statin because of some things that happened in the previous days. To my surprise, after I stopped taking the statin I would feel bad from the MCAS much earlier in the process, and then I’d also get hives, rashes, and other symptoms hours before entering pre-syncope. This gave me an opportunity to take more medicine to avoid the actual syncope event.

So, my personal experience is that taking a statin suppressed the initial mast cell disease symptoms, and that led me to go directly to syncope events without first having hives, rashes, etc.

“Hard work always beats talent if talent doesn’t work hard.”

~ Kevin Durant

Which reminds me of this Mike Ditka quote: “Effort without talent is a depressing situation ... but talent without effort is a tragedy.”


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.

Effects are related to monads

A first step in the process of understanding effects is to say that they’re related to monads, so you have to know a wee bit about monads to understand effects.

As I wrote 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).

I like to mess with book covers, so I created this alternate version of the 2021 Scala Cookbook cover. :)

Scala 3 Cookbook, alternate cover design

A great new feature in the Scala 3 Scaladoc is that you can search for methods by supplying a method/function signature. For instance, imagine that you’re new to Scala, and you have this list:

List("Ken", "Frank", "Lori")   // A

Furthermore, you know that you want to get to this list, which contains the length of each string in the first list:

List(3, 5, 4)                  // B

I had to go to the hospital in Boulder, Colorado this past weekend, and took this photo while driving in on Arapahoe Road. There are several beautiful views of the mountains and Boulder as you drive west into town on Arapahoe or South Boulder Road, and this is one of them.

Moon over the mountains over Boulder, Colorado

Without much introduction, here’s an Apache Spark “word count” example, written with Scala:

import org.apache.spark.sql.SparkSession
import org.apache.spark.rdd.RDD

object WordCount {
    def main(args: Array[String]) {
        val file = "Gettysburg-Address.txt"
        val spark: SparkSession = SparkSession.builder
                                              .appName("Word Count")
                                              .config("spark.master", "local")
        val fileRdd: RDD[String] = spark.sparkContext.textFile(file)

        // create the counts
        val counts ="[.,]", ""))
                            .map(_.replace("—", " "))
                            .flatMap(line => line.split(" "))
                            .map(word => (word, 1))
                            .reduceByKey(_ + _)

        println( "------------------------------------------")
        println( "------------------------------------------")



For more details on this example, see the Scala Cookbook, where I discuss this example, along with other Spark examples.

The first snowfall of the season happened in the Boulder, Colorado area somewhere around September 19-20, 2021. I took this photo while driving into Boulder on the morning of the 20th.

First Colorado snowfall, September 20, 2021

Note: This tutorial is an excerpt from the Scala Cookbook, 2nd Edition.

As you can tell from one look at the Scaladoc for the collections classes, Scala has a powerful type system. However, unless you’re the creator of a library, you can go a long way in Scala without having to go too far down into the depths of Scala types. But once you start creating libraries for other users, you will need to learn them. This chapter provides recipes for the most common type-related problems you’ll encounter.

Scala’s type system uses a set of symbols to express different generic type concepts, including the concepts of bounds, variance, and constraints.

A friend posted this quote on Facebook recently: “Speak to people in a way that if they died the next day, you’d be satisfied with the last thing you said to them.”

It made me think that I was happy that Lori and I had a good relationship through Facebook, and that the last time I talked to Ben, he was showing me photos from a cruise that he took, and giving me advice if I should ever go on one.