scala

Tutorials about the Scala programming language.

The target market for my book on Scala and Functional Programming alvin March 26, 2017 - 10:14am

Bonnie Eisenman perfectly captures the target market for my upcoming book on Scala and Functional Programming. How big that market is ... I don’t know ... I’m just trying to write a good book to explain functional programming in Scala in simple terms, and this is who I’m writing it for.

How to drop the first matching element in a Scala sequence

Summary: This blog post shows one way to drop/filter the first matching element from a Scala sequence (Seq, List, Vector, Array, etc.). I don’t claim that the algorithm is efficient, but it does work.

Background

While creating some Scala test code earlier today I had an immutable list of toppings for a pizza, and I got into a situation where I wanted to remove the first instance of a topping.

How to write a Scala shell script that reads input from STDIN alvin March 11, 2017 - 5:06pm

As a quick note, if you need an example of how to write a Scala shell script that reads from STDIN (standard input) and writes to STDOUT (standard output), this code shows a solution:

#!/bin/sh
exec scala -savecompiled "$0" "$@"
!#

import scala.io.StdIn

var line = ""
while ({line = StdIn.readLine(); line != null}) {
    println(line)
}
Notes on Scala for expressions, map, flatMap, and Option alvin March 10, 2017 - 1:12pm

Without any explanation, these are some of my working notes from my upcoming book on Scala and Functional Programming about a) for expressions, b) map, c) flatMap, d) Option, and e) nested flatMap and map calls.

These are equivalent (map and for)

this:

val y = x.map(_ * 2)

and this:

Async is not about performance - it’s about scalability alvin March 8, 2017 - 9:00am

“Async is not about performance – it’s about scalability.”

From this tweet by Viktor Klang, Lightbend