Tutorials about the Scala programming language.

Functional Programming, Simplified (Kindle sale) alvin October 22, 2017 - 8:46pm

Functional Programming, Simplified” is currently $15 on Amazon. Get it while you can, the price goes back up to $30 Monday night (October 23, 2017).

Functional Programming, Simplified alvin October 21, 2017 - 11:37pm

Dateline October 20, 2017: I’ve renamed my book about Scala and functional programming. The original name was, “Learning Functional Programming in Scala,” but I don’t think that sets the tone of the book quite right, so I renamed it to “Functional Programming, Simplified (Scala edition).”

You can preview and buy the book in two places:

Here’s the new “Rampaging Lambda” book cover:

Functional Programming, Simplified book cover

Functional Programming, Simplified (current contents) alvin October 21, 2017 - 11:41am

As of October 20, 2017, the contents of my book, Functional Programming, Simplified (formerly “Learning Functional Programming in Scala”) can now be summarized like this:

A Scala shell script to read HTML H1 tag attributes alvin October 20, 2017 - 3:14am

I’m putting this Scala shell script out here as a “source code snippet” so I can find it again if I need it. This file reads an input file that contains a series of HTML <h1> tags. I use this as part of a process of publishing an Amazon Kindle ebook from an HTML file, and in one of the steps of the creation process, I use this script to help create the Table of Contents (TOC) for the book.

Here’s the source code:

Functional programming in Scala: Kindle eBook, coming soon alvin October 16, 2017 - 6:21pm

In the “Good News” department, apparently a long time ago when I was pretty sick with the MCAS, I wrote a series of Scala scripts to help convert a LaTeX document into an Amazon Kindle eBook. As a result, my book on functional programming in Scala should be available as a Kindle eBook later this week.

Scala: When the sum of a list is a very large number alvin October 11, 2017 - 8:55am

As a brief note, I knew that the sum function I wrote in my book on Scala and functional programming would return a wrong value if the sum of the integers in a list was greater than Int.MaxValue, and I was curious how the built-in sum method on lists handled the same problem. It turns out that it works in the same way.

So, if you need to sum a list of integers that may exceed Int.MaxValue, you might need to write a sum function that calculates and returns the sum as a Long. (The same is true for Float and Double.)

Scala: Examples of for-expressions being converted to map and flatMap alvin October 3, 2017 - 6:03pm

Without any explanation, here are a couple of source code examples from my book, Learning Functional Programming in Scala. The only thing I’ll say about this code is that I created it in the process of writing that book, and the examples show how the Scala compiler translates for-expressions into map and flatMap calls behind the scenes.

Passing an anonymous function to SwingUtilities.invokeLater (in Scala) alvin October 3, 2017 - 5:47pm

As a quick note, if you ever need to call the invokeLater of the Java SwingUtilities class in Scala, you can pass it an anonymous function (lambda) like this:

SwingUtilities.invokeLater(() => {
    // your gui-updating code here, such as:
    for (c <- newsControllers) c.updateContent()

(I haven’t worked with Java 8 lambdas too much, but I assume that the Java syntax is similar to that.)

A milestone day alvin September 27, 2017 - 5:10pm

September 26, 2017 is a little bit of a celebration day for me. It’s the day I reached the “No new content” milestone of my book on Scala and functional programming. At this point I’ll keep editing the book contents, and I really need to work on its formatting, but I don’t have any plans to write any new lessons.

Working on the book’s index alvin September 26, 2017 - 11:49am

This past week I started working on the index for my book on Scala and functional programming. In retrospect I wish I had written the book using LaTeX (or some other technology) rather than Markdown; I would have started this process long ago.