scala

Examples of converting Scala 2 code to Scala 3 with Dotty 0.20 alvin November 10, 2019 - 5:58pm
Table of Contents1 - Significant indentation syntax with traits and classes2 - match expressions3 - for loops and if/else (and `do` and `then`)4 - try/catch syntax5 - A couple of braces not removed6 - More Dotty/Scala 3 changes

With the Dotty compiler you can convert Scala 2 code to the new Scala 3 syntax, and with the Dotty 0.20.0-RC1 release on November 4, 2019, I thought I’d see how some of the conversions work. Almost all of the changes shown below have to do with the elimination of curly braces and the use of “significant indentation” syntax, but in one example I also show the then and do keywords.

Scala: How to use higher-order functions with Option (instead of match expressions)

Table of Contents1 - Sample data2 - From match expressions to higher-order functions3 - Notes4 - Resources5 - Comments

I originally wrote a long introduction to this article about Scala Options, but I decided to keep that introduction for a future second article in this series. 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
PDF, EPUB, and MOBI versions of “Scala Book” (coming soon) alvin October 20, 2019 - 6:58pm

I worked on some tools and processes today, so sometime soon we should have PDF, EPUB, and MOBI versions of “Scala Book” available.

Hello, Scala is now Scala Book alvin October 14, 2019 - 5:09pm

One small step for me, and I don’t know if it will help mankind at all. But Hello, Scala is now called Scala Book, and you can find it here on scala-lang.org.

An example of Union Types in Scala 3 (Dotty) alvin October 10, 2019 - 9:33am

Here’s an example of Union Types in Scala 3 (Dotty). This image comes from this Martin Odersky video.

Different perspectives from book reviewers

I recently had a discussion with two people I’m working on a book with, where they are essentially very active reviewers. I like to write with enthusiasm, so I made a particular statement in the book. One person said they thought it was motivating — which was my intent — but the other person said it made them wary. I thought it was fascinating to get such different perspectives.

A quiet, attractive new programming language alvin September 29, 2019 - 8:00pm

Here’s some source code that demonstrates a quiet, concise, and attractive new programming language I’d enjoy using:

Scala 3 (Dotty), September 30, 2019

Scala 3: No parentheses in control structures alvin September 28, 2019 - 7:55am

When I originally saw the first image, I thought it was a “This would be nice in Scala 3 (Dotty)” idea. But then I found the “No parentheses in control structures” pull request shown in the second image. Here’s a link to that pull request.

How to search for multiple regex patterns in many files with `ffx`

I recently created a command I named ffx that lets you search your filesystem for files that contain multiple strings or regular expressions. This post describes and demonstrates its capabilities. (There’s a little video down below if you want to see how it works before reading about it.)