There are many nice cartoons/illustrations in Eckhart Tolle’s book Guardians of Being: Spiritual Teachings from Our Dogs and Cats, and this “Shtop Thinking” cartoon is one of my current favorites. (The book is a collaborative effort between Mr. Tolle and Patrick McDonnell, artist/illustrator/cartoonist who may be most well known for his “Mutts” cartoons.)
Back when I was writing Functional Programming, Simplified I started to write a little Scala/FP “To-Do List” application that you can run from the command line, based on a similar application in the Learn You A Haskell For Great Good book. For reasons I don’t remember, I decided not to include it in the book, and forgot about it until I started using GraalVM (“Graal”) recently.
If you’re interested in understanding the Cats library, I’m a big fan of the book, Scala with Cats (formerly known as Advanced Scala with Cats). Noel Welsh and Dave Gurnell have a simple writing style, with good examples. Being an older person, I only wish a print version was available.
This page is a collection of popular tools, libraries, and frameworks for the Scala programming language.Back to top
typelevel.org has a nice article on shared state in functional programming.
As a final example of how to use type classes in Scala, I’ll show how to repeat the example from the previous lesson using the open source “Cats” FP library for Scala. With the examples you’ve seen already, this will be a quick process.
Step 1 is to clone my source code for this lesson, which is available at this URL:
If you looked at the source code for the Domain Modeling lessons you probably noticed that I said one thing, but did another. I said that I liked the approach of not including any methods in my
case classes, but then I wrote this code:
“A type class is an interface that defines some behavior. More specifically, a type class specifies a bunch of functions, and when we decide to make a type an instance of a type class, we define what those functions mean for that type.”
The source code for all of the type class lessons is available at the following URL:
In this section of the book I’ll cover Scala type classes, a programming technique that lets you add new behavior to closed data types. The use of type classes isn’t strictly limited to the functional programming style, but because they’re used so much in the Cats library — an FP library for Scala — it’s important to know how they work.