I’m working on a little app for my Scala & functional programming book I currently call “Future Board.” It works a little like Flipboard in getting news headlines from different sources, but it uses Scala Futures and a few other functional programming techniques.
“Monad transformers are not too intuitive, especially in Scala, and are known to produce hard to understand code structure.”
~ Debasish Ghosh, Functional and Reactive Domain Modeling
Here’s a little example of how exceptions work with Scala Futures, specifically looking at the
onComplete ‘Failure’ case.
In this example I start three Futures that run for different lengths of time, and the shortest-running
Future throws an exception:
Version 0.1.4 of “Learning Functional Programming in Scala” is now available. The latest changes are:
- 13 new chapters on the
StateT monad and monad transformers
- Ten new chapters on Domain Modeling
- Two new chapters on ScalaCheck
- New appendices on Anonymous Functions, and using
val in traits
- The PDF now has small 113 chapters, four appendices, and is 983 pages long
To accompany this latest update, the book is on sale for a few days.
The next release of Learning Functional Programming in Scala should be available by the end of the day (my day here in Colorado) Tuesday, September 12, 2017. If I add everything in, it will contain over 30 new lessons.
Here are a few notes about using Scala traits as mixins, specifically:
- The order in which mixed-in traits are constructed
- The order in which overridden methods in traits are called when multiple traits are mixed in
I was working on some new code for my functional programming in Scala book today. At one point I thought everything looked okay, and then I decided to generate some Scaladoc to see what certain things looked like. Admittedly I’m a bit tired today, but when I saw that Scaladoc I thought, “Good grief, Al, what sort of ugly API have you created?”
In Scala you can declare a type alias. Typically you do this to create a simple alias for a more complex type.
Using a type alias to simplify a complex type
For example, on this page I note a good example where someone on StackOverflow first defined a type alias named
Row, and then created a second type alias named
Matrix as a list of rows: