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

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

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

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.

This is one view of Mother Nature pouncing on Boulder, Colorado. (Boulder and the Rocky Mountains are under that blanket of clouds.)

Boulder, Colorado flooding, 9/12/2013

I can’t find the exact Ram Dass story I’m looking for or the specific details, but it goes something like this ... after his initial work with Maharaji in India, Ram Dass came back to the U.S. and lectured on spirituality. As he says it, “I was supposed to be a spiritual teacher with no attachments, but the reality is that wherever I went, I had these nine boxes of things that were of sentimental value to me.” So he’d go from city to city lecturing about how to have no attachments, and all the time he was lugging these nine boxes around behind him.

One day he realized that he really needed to give up his attachments to those things, so he did his best to give everything away, but at the end he still had three boxes remaining. “I’m sorry, Maharaji,” he said, “that’s all I can do for now, this is killing me.”

“That was a few years ago,” Ram Dass said. “Now I have thirteen boxes.”

:)

While at a doctor’s office, a nurse asked me what makes Scala special.

I said, “You know how some spoken languages sound beautiful, like Italian or French? In the same way, some programming languages look beautiful, like Scala 3. So we use other languages when we’re forced to, but we use beautiful languages because we want to.”

As a quick note to self, I just used these contents in a Scala/sbt build.sbt file when working with the GraalVM native-image command (and sbt plugin). I share these here so I can remember how to specify command-line options for the native-image plugin in the build.sbt file:

lazy val sbtmkdirs = (project in file("."))
    .enablePlugins(NativeImagePlugin)
    .settings(
        name := "http_client",
        version := "0.1",
        scalaVersion := "3.0.1",
        Compile / mainClass := Some("foo.HttpClient"),
        // these are the native-image options i used
        // to work with HTTP and HTTPS (though I don’t know
        // if they are all needed)
        nativeImageOptions ++=
            Seq(
                "-H:EnableURLProtocols=http",
                "-H:EnableURLProtocols=https",
                "--enable-url-protocols=http,https",
                "--enable-https",
                "--enable-http"
            )
    )

scalacOptions ++= Seq(
    "-deprecation",
    "-explain",
    "-explain-types",
    "-new-syntax",
    "-unchecked",
    "-Xfatal-warnings",
    "-Xmigration"
)

It’s also helpful to see that sbt/build.sbt Compile / mainClass syntax, because that’s currently hard to find on the internet

If you’re finding Akka Typed hard to learn, fear not, it took me almost two days to get the simplest of their Scala examples working. And I had already written the original Scala Cookbook, and already knew how to use Akka Classic!

As a remedy to this problem, I wrote about how to use Akka Typed in the 2021 version of the Scala Cookbook. In the book I show some of the simplest possible Akka Typed examples, so you won’t have to waste two days of your life trying to get a simple example running.

Here in August and September, 2021, the Scala Cookbook is a best-selling new programming book in both the OOP and FP categories. And as I found out yesterday, a great thing about writing for O’Reilly is that if you write a book for them, they’ll send you a bunch of free copies, even when the book is almost 800 pages long. Makes for a great unboxing experience!

Scala Cookbook unboxing experience (2021 best-selling new release)

Personal Diary, September 2, 2010, Wasilla, Alaska:

I bought a fig at the grocery store today. Turns out they’re about the size of a Hershey’s Kiss. The checkout person just looked at me. “One fig? You want to buy one fig?”

“Yes, just one. I want to see what they taste like.”

She put the fig in the bag without weighing it. “I’m pretty sure I can give you one fig without charging you for it,” she said.

If I had a flower for every time I thought of you, I could walk in my garden forever.

One of the things I love about Peter Gabriel’s music is how brutally honest his lyrics are. Sure, there’s imagery and metaphor and other things that make music great, but like these lyrics from Washing of the Water, the lyrics are just raw and emotive:

’til the washing of the water
Make it all alright
Let your waters reach me
Like she reached me tonight

Letting go, it’s so hard
The way it’s hurting now
To get this love untied
So tough to stay with thing
’cause if I follow through
I face what I denied
I get those hooks out of me
And I take out the hooks that I sunk deep in your side
Kill that fear with emptiness
Loneliness I hide

River, oh river, river running deep
Bring me something that will let me get to sleep
In the washing of the water will you take it all away
Bring me something to take this pain away

I believe it was Stevie Nicks who sang about the Cooler of Love, and wouldn’t we all like to drown there.

The Cooler of Love, Longmont, Colorado

I’m happy to report that the Scala Cookbook for Scala 3 — a.k.a., the Scala 3 Cookbook — is now the #1 new release in Amazon’s functional programming category, as of late August, 2021. This comes on the heels of already being the #1 new OOP book.

Scala Cookbook: #1 new release in functional programming

As a quick note today, in this post I’ll share some examples of the Scala map method as it works on sequences like the List, Vector, and Seq classes.

map == transform

Basically you can think of map as meaning transform: it lets you transform one collection into another. For instance, these examples in the Scala REPL show how to transform a list of strings into a list of integers, where the integers correspond to the length of each string:

It turns out he had a little magic in him: With his overabundance of unconditional love, he could change people. I know, because he changed me.

~ from this story about Zeus

I really like this quote about Ichiro Suzuki from this espn.com article. I never thought that way as a batter or as a pitcher, but as a batter I can see how that mentality would help. It’s like you’re in a mano a mano battle with a pitcher about four times a game. I reminds me of an attitude that you need in a sport like wrestling. It also reminds me of warriors yelling “Certain Victory!” before entering into battle, or yelling “Battle!” in the movie Michael.

Ichiro's samurai pose

I’m happy to report that the second edition of the Scala Cookbook — just completed in August, 2021 — is a best-selling new release on Amazon.com in both the object-oriented programming (OOP) and functional programming (FP) categories. This is thanks to the fact that Scala 3 is an excellent language to use for both OOP and FP development.

Scala Cookbook, a best-selling new release (OOP and FP)

“Never make someone a priority, when all you are to them is an option.”

(I saw this quote this morning, and I was debating about whether I like it, but it does fit with a relationship of late.)