My new book, Learning Functional Programming in Scala, is currently available as a PDF you can purchase for just $10 US. (The price is going up to $25 this Saturday.) Details are listed below.Back to top
What’s new (June 25, 2017)
If you’ve been following along with me recently, the latest changes are:
The funny thing about writing the Scala Cookbook is that it started as a whim. I was just about to leave for a vacation at the beach, and right before I turned off the computer, a thought flashed in my mind, “I should contact the people at O’Reilly about writing a cookbook for Scala.” I then had a doubt that they would actually do it, but I applied the “What the heck” rule — i.e., “What the heck, what do I have to lose?” — and sent the email.
I dug around the internet for a few minutes, found the correct O’Reilly email address, sent them a message, turned off the computer, and drove to the beach. While I was at the beach the publisher wrote and said, “Love it, send me a full proposal!”
So if you’re thinking about doing something, but are afraid or uncertain about doing it ... apply the “What the heck” rule, and give it a shot. :)
Update 1: The next version of my book on Scala and functional programming will be released later this week.
Update 2: The price of the book will be increased to $25 on July 1, 2017.
Scala is a great language in many ways. One great feature is that you can use it as a “Better Java” (i.e., as an OOP language), and you can also use it as a pure FP language. While some people prefer one extreme or the other (not unlike extremist Republicans and Democrats in the U.S.), I appreciate that this lets you find a “Middle Way” of using the best features of both approaches.
Without much introduction or discussion, here’s a Scala example that shows how to read from one text file while simultaneously writing the uppercase version of the text to a second output file:
This scala-lang.org documentation page shares a good reason to use “sealed” traits and classes: When you do this, the compiler can easily tell all of the subtypes of your class or trait, and therefore you don’t need to add a default, “catch-all” case in your Scala
As a quick note, if you’re interested in using the IO monad described in this IO Monad for Cats article, here’s the source code for a complete Scala
App based on that article:
The people at underscore.io have made their books on Scala and functional programming free (or “donationware,” if you prefer). I’ve found the Advanced Scala with Cats book to be particularly good, and well worth a donation.
(Full disclosure: I didn’t pay for the Advanced Scala book when I first downloaded it, then went back and tried to pay for it, but the Gumroad website wouldn’t let me do that.)
After the 0.1.2 release of Learning Functional Programming in Scala, it occurs to me that I need to be more explicit about my goals for the book. Some people seem to think that I’m trying to “sell” functional programming. That’s not the case at all. I’m just trying to be a reporter and explain what I’ve learned about FP after reading dozens (hundreds?!) of articles and many books on FP, learning Haskell, trying to apply these techniques to my own code, etc. I’ll explain this further in the next release of the book.