functional programming

Next version of Learning Functional Programming in Scala alvin August 16, 2017 - 10:25am

I get to have another operation (surgery) next week, but I still hope to have the next version of my book on Scala and functional programming available by the end of the month.

Scala: Handling nested Options with flatMap and for alvin August 7, 2017 - 5:47pm

Summary: In this article I show a couple of ways to extract information from optional fields in your Scala domain models. This example is a little contrived, but if you have a situation where one Option instance contains one or more other Options, this article may be helpful.

There are times when you’re creating your domain model when it makes sense to use optional fields in your case classes. For instance, when you model an Address, the “second street address” isn’t needed for all people, so making it an optional field makes sense:

“Pure functional programming is programming with mathematical functions” alvin August 6, 2017 - 2:13pm

“Pure functional programming is programming with mathematical functions.”

~ Erik Meijer

Scala “lint” tools alvin August 5, 2017 - 5:01pm

As a quick note, I was just looking into the state of Scala “lint” tools, and found ScalaStyle, WartRemover, and Scapegoat.

This 2014 post states, “Those interested in FP purity in a Scala world, you’ll want WartRemover.” (Of course that recommendation may have changed by now.) The current ScalaStyle website states, “Scalastyle is used as part of the grading framework for the course Functional Programming Principles in Scala by Martin Odersky on Coursera.”

Scala 2.12: Either is biased, implements map and flatMap

While reading the excellent Scala/FP book, Advanced Scala with Cats, I was just reminded that Scala’s Either class was redesigned in Scala 2.12. Prior to 2.12, Either was not biased, and didn’t implement map and flatMap methods. As the image from the book shows, Either is redesigned in 2.12 to include those methods, so it can now be used in Scala for-expressions as shown.

(I write about biasing in my book, Learning Functional Programming in Scala.)

An initial review of Functional and Reactive Domain Modeling

I’m not yet sure if I like the book Functional and Reactive Domain Modeling, but one thing is for sure: I couldn’t begin to understand it if I didn’t first do the research to write Learning Functional Programming in Scala. The author immediately jumps into monads as if they are commonly understood, and also designs his functions as “modules” in a very Haskell-ish way. I’m not saying the book is bad, just that it has a high barrier to entry.

Notes from “Thinking Functionally with Haskell”

I’m always curious about how people think, and these days I’m most interested in how functional programmers think about programming problems. Along those lines I found a good blog post (tutorial) titled, “Thinking Functionally with Haskell”, and these are my notes from that post: