scala

Tutorials about the Scala programming language.

Hello, Scala (free preview)

If you like free things, here’s a link to a free preview of the new version of my book, “Hello, Scala.” The book is 257 pages long, and the free preview contains the first 120 pages of it, so I hope it’s a significant preview.

The new version of the book isn’t currently available for sale, but I hope to release print, PDF, and Kindle versions of it in the next few weeks.

Updates for “Hello, Scala”

This page contains updates for my book, Hello, Scala. As I find good, new resources related to the book I’ll share them here, along with errata related to the book.

(No updates yet.)

JMH, an SBT plugin for running OpenJDK JMH benchmarks

JMH is an SBT plugin for running OpenJDK JMH benchmarks. Per its docs, “JMH is a Java harness for building, running, and analysing nano/micro/milli/macro benchmarks written in Java and other languages targeting the JVM.”

They also recommend reading an article titled Nanotrusting the Nanotime if you’re interested in writing your own benchmark tests.

Scala: How to list files and directories under a directory

When using Scala, if you ever need to list the subdirectories in a directory, or the files under a directory, I hope this example is helpful:

import java.io.File

object FileTests extends App {

    // list only the folders directly under this directory (does not recurse)
    val folders: Array[File] = (new File("/Users/al"))
        .listFiles
        .filter(_.isDirectory)  //isFile to find files
    folders.foreach(println)

}

If it helps to see it, a longer version of that solution looks like this: