Tutorials about the Scala programming language.
If you ever need to parse JSON stock data from alphavantage.co using Scala, here’s a test class I just wrote that uses Lift-JSON.
The JSON data format
First, here’s the JSON I get back from them:
If you ever wondered what Digital and Print book sales look like for a technical book (a computer programming book, in this case), here you go. This is a slightly cleaned up chart that O’Reilly provides to me for sales of the Scala Cookbook over time, showing eBook sales vs the printed book sales.
As a short note, here’s some Scala source code that shows how to write a
foldLeft function using recursion:
After yesterday’s Scala nested Option + flatMap/for example, here’s another example of plowing through nested Options with
flatMap. First, start with some nested options:
val o1 = Option(1) val oo1 = Option(o1) val ooo1 = Option(oo1)
Here are those same three lines, with the data type for each instance shown in the comments:
Here’s a little fun with Scala functions, including the use of
scala> val add1 = (i: Int) => i + 1 add1: Int => Int = <function1> scala> val double = (i: Int) => i * 2 double: Int => Int = <function1> scala> val addThenDouble = add1 andThen double addThenDouble: Int => Int = <function1> scala> addThenDouble(1) res0: Int = 4 scala> val doubleThenAdd = add1 compose double doubleThenAdd: Int => Int = <function1> scala> doubleThenAdd(1) res1: Int = 3
Here’s some source code for a little Scala “date utilities” class:
In this article I share some examples of Scala’s Scaladoc syntax, including common Scaladoc tags, and the wiki-style of markup that Scaladoc supports.
(this space left open to make room for the table of contents over there -->)
Back to top
An example of Scaladoc tags and wiki formatting
You can mark up your source code using Scaladoc tags as well as a wiki-like syntax. The following code shows many of the Scaladoc tags and a few of the wiki-style markup tags:
Here are a couple of “string to date” and “date to string” methods. They’re written in Scala, but are easily converted to Java. They only use the Java