With the Dotty compiler you can convert Scala 2 code to the new Scala 3 syntax, and with the Dotty 0.20.0-RC1 release on November 4, 2019, I thought I’d see how some of the conversions work. Almost all of the changes shown below have to do with the elimination of curly braces and the use of “significant indentation” syntax, but in one example I also show the
If you ever need to convert a Java array into a Stream, there are at least two ways to do it.
1) Converting an array to a Stream
First, to convert the entire array to a
Stream, use the
Stream.of static method like this:
If you ever need to convert Docbook to AsciiDoc, this Pandoc command seems to work well:
pandoc --wrap=none -f docbook -t asciidoc \ DocbookFile.xml > AsciiDocFile.adoc
This short blog post contains a collection of Scala number and date examples. I created most of these in the process of writing the Scala Cookbook. Unlike the Cookbook, I don’t describe the examples here much at all, I just show the examples, mostly as a reference for myself (and anyone else that can benefit from them).
Scala numeric types
Scala has these numeric types:
If you ever need to convert HTML to plain text using Scala or Java, I hope these Jsoup examples are helpful:
Nothing major here today, but here’s some source code to start a little Scala “date utilities” class:
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
I’m looking into producing my Scala/FP book as a PDF, and as part of that I have been looking into Pandoc. With the exception of converting HTML tables into other formats such as Markdown or LaTeX, Pandoc has been working well so far.
Here are a couple of Pandoc commands to show you how easy this is:
I was working on a Haskell factorial function (which turned out to be easy) and decided I wanted to write a program to prompt a user at the command line for an
Int, and then do the factorial of that
I quickly learned that this required a
Int conversion, which I wanted to do safely (I didn’t want my program to blow up). Technically what I do is actually a
Maybe Int conversion, as you can see in this code: