scala

Tutorials about the Scala programming language.

An attempt at a JavaFX menubar and keystroke listener alvin February 4, 2018 - 3:29pm

This code for creating a JavaFX menubar and handling a keystroke/key-combination didn’t work as desired, but I think it’s on the right track:

An example of using ‘break’ in a Scala for loop alvin February 1, 2018 - 9:37am

Here’s a little example of how to use a break in a Scala for loop:

A Scala method to replace a few “bad” characters alvin February 1, 2018 - 9:13am

Here’s a little Scala method I wrote to replace some “bad” characters that won’t print properly on my Radio Pi display:

def replaceBadCharacters(s: String): String = {
    s.replaceAll("“", "\"")
     .replaceAll("”", "\"")
     .replaceAll("‘", "\"")
     .replaceAll("’", "\"")
}

There are other ways to solve this problem, but I threw this together as a quick patch until I can figure out why the Phosphor screen saver on the Raspberry Pi won’t print those characters that I’m replacing.

What’s the easiest way to learn functional programming? alvin January 28, 2018 - 3:40pm

People occasionally ask me, “What’s the easiest way to learn functional programming?” If you look at all of the books on the right side of this image, I can tell you that reading all of those books wasn’t an easy way to learn functional programming (FP):

IMHO there’s a much easier way to learn the FP basics: I’ve made almost 40% of my book, Functional Programming, Simplified, freely available.

The notes that became Functional Programming, Simplified alvin January 23, 2018 - 9:24pm

Back in 2016 I posted this photo on Facebook with the caption, “The current minefield that may one day grow into a book.” Those notes eventually grew into Functional Programming, Simplified.

How to use Lift-JSON to parse JSON array data alvin January 22, 2018 - 6:52pm

If you ever need to parse JSON stock data from alphavantage.co using Scala, here’s a test class I just wrote that uses Lift-JSON.

The JSON data format

First, here’s the JSON I get back from them:

What Digital (eBook) and Print sales look like for a computer programming book alvin January 22, 2018 - 10:27am

If you ever wondered what Digital and Print book sales look like for a technical book (a computer programming book, in this case), here you go. This is a slightly cleaned up chart that O’Reilly provides to me for sales of the Scala Cookbook over time, showing eBook sales vs the printed book sales.