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

Here’s a little example of how to use the Scala 3 @infix annotation to create an infix method, while using the technique with extension methods at the same time:

import scala.annotation.infix

extension (i: Int)
    @infix def plus(j: Int) = i + j
    @infix def times(j: Int) = i + j

That code adds the extension methods plus and times to the Scala Int class, while also letting them be used as infix methods. The REPL shows the result:

scala> 1 plus 1
val res0: Int = 2

scala> 2 times 2
val res1: Int = 4

In summary, if you wanted to see how to write infix methods and extension methods with Scala 3, I hope this example is helpful

This is a view of the Independence Mine area in Hatcher Pass, Alaska, from October, 2010.

View of Independence Mine, Hatcher Pass, Alaska

Hatcher Pass, Alaska, October 20, 2010.

Hatcher Pass, Alaska

This may look like a bad roller coaster ride, but it’s part of the Independence Mine in Hatcher Pass, Alaska. It operated as early as 1897, but was used more in the early-to-mid 1900s.

Independence Mine railroad in Hatcher Pass, Alaska

If you’re using Git and need to compare two recent versions of the same file, I can confirm that this git diff command works:

git diff HEAD^ HEAD nodeBlog.scala.html

That command compares the second-most recent version of the file (given by HEAD^) to the most recent version of the file (HEAD). In this example I want to see the detailed differences of these versions of the file named nodeBlog.scala.html. In my case, the result of this command is shown in the image.

As shown on this SO page, there are other ways to issue this Git command, and similar commands.

In summary, if you need to compare two versions of a file when using Git, I hope this example is helpful.

Git: How to compare two different versions of a file

“That was a lot of kidney stones.”

~ the surgeon, October, 2020

This is a field of prairie dogs in the foreground and mountain ranges in the background, near my new home in Longmont, Colorado.

Prairie dogs and mountain ranges, Longmont, Colorado

I originally wrote a long introduction to this article 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:

  • idiomatic Scala code involves never using null values
  • because you never use nulls, it’s important for you to become an expert at using Option, Some, and None
  • initially you may want to use match expressions to handle Option values
  • as you become more proficient with Scala and Options, you’ll find that match expressions tend to be verbose
  • becoming proficient with higher-order functions (HOFs) like map, filter, fold, and many others are the cure for that verbosity

Given that background, the purpose of this article is to show how to use HOFs rather than match expressions when working with Option values.

As a brief note today, here are a couple of comparisons of Java’s Optional and Scala’s Option.

First, here’s a Scala makeInt method written with Option in Scala 3:

def makeInt(s: String): Option[Int] = 
    try
        Some(s.toInt)
    catch
        case e: NumberFormatException => None

and here’s the same method written with Optional in Java:

Last night we had all sorts of beautiful whispy clouds, throughout the Louisville/Lafayette/Erie Colorado area. For those who can see my Facebook stuff, you can see several more photos at this link.

Whispy clouds, Louisville, Colorado

A crazy thing about mast cell disease is that you can be doing perfectly fine, all systems normal, and then you eat something wrong and two hours later you wish you were dead, or at least not conscious.

Every day I take a little blue pill.

Two of them, actually.

And they’re extremely helpful.

Later this week I’ll be giving birth to septuplets. Kidney stones, that is. Seven of them.

They’re going to be surgically removed, and whatever chemicals are in these little blue pills they gave me helps to reduce the spasms caused by the stones being stuck in places where they shouldn’t be.

My book, Functional Programming, Simplified — 4.5-star rated on Amazon, and their 6th-best selling functional programming book — is currently on sale in three formats:

PDF Format
Just $15 on Gumroad.com
(December sale!)

PDF version of Functional Programming, Simplified

Paperback Book
$39.99 on Amazon
 

Print version of Functional Programming, Simplified

Kindle eBook
$14.99 on Amazon
 

Kindle version of Functional Programming, Simplified

Rafael Nadal, October 9, 2020: “It’s important to go through all the process. You have to suffer. You can’t pretend to be in a final of Roland Garros without suffering. That’s what happened there. But I found a way, no?”

Yesterday afternoon I took a nap, and for a while I was lucid while I was sleeping, and with nothing better to do, I worked on my grocery shopping list. I could easily remember what I needed, and made mental notes about those items. Unfortunately after I woke up I didn’t think about this for a while, and later in the evening I couldn’t remember a darned thing I needed.

I had a similar situation a few weeks ago, but in reverse. I was emailing with a friend about motorcycles, and for the life of me I couldn’t remember where everything is on a bike, the gas, clutch, brakes, how the gears work, etc. But two nights later I had a vivid dream of riding a motorcycle, and once I became lucid in the dream “I” saw that I (some other “I”) knew exactly how everything worked. After I woke up I was able to recall everything, and was comfortable that I was correct.

Both events blew me away in terms of how accurate my memory is when I’m asleep. It makes me wonder why I can’t remember these things when I’m awake.

This is part of the mountain view from the Foothills hospital in Boulder, Colorado.

The mountain view from the Boulder, CO Foothills hospital

Very soon I’ll be under anesthesia for the 19th time in my life. Hopefully when you get to 20 you get a prize. :)

I was listening to a book by Lisa Scottoline named Killer Smile, and a woman in her seventies told a woman in her late 20s or early 30s to be brave.

“I don’t know if I can be brave,” the younger woman replied.

“Don’t worry about that,” the older woman said. “If you can’t be brave, just be determined.”

That struck me as smart. I’ve often thought that I don’t know what brave is, but we all know what it is to be determined.