scala

Tutorials about the Scala programming language.

A small Scala 2 project converted to Dotty

If you want to see a somewhat larger example of Dotty source code than I’ve shown before, I just took a little time to convert a small Scala 2 project over to the new/current Dotty syntax (i.e., the Dotty syntax supported by the Dotty 0.21 release, circa January, 2020).

Think of the Scala collections’ map method as “transform”

I’ve written this before, but when I saw this “pseudocode to Scala code” example in the book Functional Thinking, I thought it was worth mentioning again: If you have trouble grokking the Scala map method, think of it as being named transform instead. It transforms an input collection to an output collection, based on the algorithm you supply.

For those coming from the OOP world, I think “transform” is a better word because it is more meaningful, at least initially.

Scaladoc-driven API design

I was working on some new code for my functional programming in Scala book today. At one point I thought everything looked okay, so I decided to generate some Scaladoc to see what certain things looked like. Admittedly I’m a bit tired today, but when I saw that Scaladoc I thought, “Good grief, Al, what sort of ugly API have you created?”

For some reason, seeing the Scaladoc helped me easily see the errors of my way. I’m not sure that I’ll ever be promoting a “Scaladoc-driven API design” process, but seeing the Scaladoc generated from my code sure helped today.

~ a note from August 30, 2017

How to use the Lightbend Config library in a Scala or Java application

Table of Contents

  1. Solution
  2. Discussion
Table of Contents1 - Solution2 - Discussion

Scala problem: You want to be able to read configuration files that are written in the Lightbend “Config” file format.

Back to top

Solution

Lightbend — initially named Typesafe — created a configuration file format named HOCON, which stands for, “Human-Optimized Config Object Notation.” As an example, a small HOCON configuration file looks like this:

Notes on using Dotty (Scala 3), SBT, and VS Code together

As a note to self, here are some ways to work with Dotty (Scala 3), SBT, and VS Code (Visual Studio Code).

Create a Dotty project:

sbt new lampepfl/dotty.g8

Launch VS Code inside that project directory, with Dotty support:

sbt launchIDE

Start SBT as usual:

sbt

Those notes are just a reminder for myself, but hopefully they’ll also help others work with Dotty, SBT, and VS Code.