Posts in the “scala” category

How to set the Scala version in the SBT build.sbt configuration file

SBT FAQ: How do I set the desired Scala compiler version in the SBT build.sbt configuration file?

Set the value of the scalaVersion variable in your SBT build.sbt file. For instance, to use Scala 2.9.2, put an entry like this in the build.sbt file:

scalaVersion := "2.9.2"

To use Scala 2.10.0, put an entry like this in the build.sbt file:

Scala: How to rename a class when you import it (a 'rename on import' syntax example)

Scala offers a cool feature where you can rename a class when you import it, including both Scala and Java classes. The basic syntax to rename a class on import looks like this:

import scala.collection.mutable.{Map => MMap}

and this:

import java.util.{HashMap => JavaMap}

If all you needed to know, I hope those "rename on import" syntax examples were helpful.

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.

Scala web service frameworks

I can never remember the name "unfiltered", so yesterday I kept trying to google for "web service framework", and to my surprise, Google wasn't showing unfiltered. In fact, it didn't show other tools like Scalatra, though it did show Play in the top ten.

So today's post is an effort to help Google out a little bit here. If you're looking for good Scala web service frameworks, check out these tools:

“Hello, Scala” PDF is now free

November 26, 2019: The PDF version of my book “Hello, Scala” is now free, and you can download it by clicking on the image below.

Future “updated and improved” versions of the book are being released as Scala Book. Currently an HTML version of the book is available here on the scala-lang.org website, and we’ll have PDF, MOBI, and ePub versions of that available once the creation process is automated and a few other issues are resolved.

But for now, click on the image below if you’d like to download the PDF of Hello, Scala for free:

Hello, Scala PDF

Scala code to find (and move or remove) duplicate files

My MacBook recently told me I was running out of disk space. I knew that the way I was backing up my iPhone was resulting in me having multiple copies of photos and videos, so I finally decided to fix that problem by getting rid of all of the duplicate copies of those files.

So I wrote a little Scala program to find all the duplicates and move them to another location, where I could check them before deleting them. The short story is that I started with over 28,000 photos and videos, and the code shown below helped me find nearly 5,000 duplicate photos and videos under my ~/Pictures directory that were taking up over 18GB of storage space. (Put another way, deleting those files saved me 18GB of storage.)

ADTs in Scala 2 and Scala 3

I’ll write about this a little more when I’m awake, but here’s a little look at ADTs implemented in Scala 2 (with traits and case objects) and Scala 3 enums.

FP is not about not having side effects at all

“I though it was obvious, but apparently it's not. FP is not about not having side effects at all, otherwise it would be useless. It's just about deferring them for as long as possible, that's all.”

~ Alessandro Lacava, in this tweet