scala

“Monad transformers are not too intuitive” alvin September 19, 2017 - 9:50am

“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

A look at how exceptions work with Scala Futures and the onComplete ‘Failure’ case alvin September 18, 2017 - 12:53pm

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”

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 def vs 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.

A few notes about using Scala traits as mixins (construction order, overridden methods) alvin September 7, 2017 - 7:00am

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

SBT: Example build.sbt variables/settings (from PPrint) alvin August 31, 2017 - 9:47am

Because I think it’s often best to “learn by example,” I’ve become a connoisseur of SBT build.sbt examples, and this build.sbt file from Lihaoyi’s PPrint project demonstrates a lot of SBT variables:

Scaladoc-driven API design alvin August 30, 2017 - 4:44pm

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?”

Scala type aliases (syntax, examples)

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: