Functional programming (FP) is a programming style emphasizing functions that return consistent and predictable results regardless of a program's state. As a result, functional code is easier to test and reuse, simpler to parallelize, and less prone to bugs. Scala is an emerging JVM language that offers strong support for FP. Its familiar syntax and transparent interoperability with existing Java libraries make Scala a great place to start learning FP.
Functional Programming in Scala is a serious tutorial for programmers looking to learn FP and apply it to the everyday business of coding. The book guides readers from basic techniques to advanced topics in a logical, concise, and clear progression. In it, they'll find concrete examples and exercises that open up the world of functional programming.
Purchase of the print book comes with an offer of a free PDF, ePub, and Kindle eBook from Manning. Also available is all code from the book.
Full Disclosure: I was a Technical Reviewer for this book
Functional Programming in Scala is a very interesting, but extremely challenging book. One thing it is not is a Scala book, despite that the name may make you think. This is a book about Functional Programming itself, and the language it uses for examples simply happens to be Scala. The content borders on academic in nature, if you know any nerdy neckbeards who are super into Functional Programming and like talking about monads and functors and whatnot, you know the kind of stuff you're getting.
Things are well explained, but the information is extremely dense. I reviewed this book, so I wound up reading the same sections three or four times through the different revisions, and I *STILL* struggled with understanding everything. This book is not for the faint of heart, and it's not the kind of book you can passively read. It's really more like a course or a textbook for one.
One really interesting thing you wind up doing in the book by working through examples is building up classes that actually could replace some of the classes in the scala standard library. It's a really fascinating way to see what the library classes are up to under the hood, it's all very eye-opening.
Overall, this is one of the most informative books on Functional Programming I've ever heard, but I can't help but lament how difficult the material is. I don't know if it's a problem with presentation or if it's just me, but I repeatedly had that nagging feeling of "holy crap, I'm too stupid for this stuff" while reading. When I'd submit feedback for the authors, I often imagined them seeing it and rolling their eyes at what a bozo I was, then pushing up their glasses and proving something on a chalkboard. The fact that most of my feedback was actually incorporated into the book is the only reason I don't feel like I must be a complete idiot, but without that kind of feedback I wonder if other readers will feel similarly to how I did. If so, let me assure you, you are not alone, this book is very, very difficult.
This book should be required reading for anyone wanting to really learn and understand Scala. It's not that the book will necessarily give you mastery of the language -- only time and experience gained through writing lots of code can do that, though they help by giving the reader lots of good exercises. But it will alter your view of the language and very likely teach you a new way of approaching problems. The authors are both expert Scala engineers with deep understanding of the principles of functional programming. Their approach is illuminating, in particular, in showing how you can apply the type system and referential transparency to solve problems using very generalizable patterns.
Addendum to my earlier posting of this, initially very brief, review:
First, it's worth noting that this book in no way requires you to learn or use Scalaz, though both authors are contributors to that library. It will teach you what you need to better understand Scalaz, but it also leaves a lot out. For example, the current pre-release draft of the book doesn't even mention type classes. In my opinion, this is a good thing. There are other books, such as Joshua Suereth's fantastic Scala in Depth, that do a very good job of this already. And covering this material here would only take away from the core of what this book attempts to teach.
Finally, I should note that I was both a technical reviewer of earlier drafts and did the final technical proofreading. So hold me responsible for any errors that slipped through!! Well, not really! ;~) I was (well, will be) compensated for both of these (a free book in the first case and a small monetary amount in the second), but I can tell you truthfully that in no way did this influence my review of this book. If anything, my experience proofreading this gave me an interesting insight into the book. Having tech reviewed and proofread many other books, I was floored by how few technical errors (remember, I was not reviewing their language or grammar) I was able to find. I personally believe this may demonstrate something interesting about the diligent effort the authors put into this book.
Additional notes:
This book is a good one to work through with others, particularly given the exercise driven nature of it. At Janrain, where I am currently employed, we started a study group to work through it. We initially planned a week per chapter, but found even this was overly aggressive at times. It's best to find the rate that works for the group and adjust as needed.
As I mention in one of my comments below to my friend and coworker Sean, this is probably nto the best book to use as an introduction to Scala. The authors do a good job of introducing the features you need to work through the book (though I did see a few places where they leave the reader to find more on her own), it won't give you the breadth you really need to become proficient. That said, if you do choose to pick up a book, such as Scala for the Impatient, you can certainly work through both in tandem if you're really in a hurry.
1. I hate scala. I hate object oriented programing and scala gives you the worst of OO combined with the baffling complexity of functional programming.
2. I am not a good functional programer.
This book is dense, dense, dense. I don't think you could use it to learn functional programming unless you already understand functional programming.
I'm going to try Clojure and see if that works any better.
It is safe to say that “Functional Programming in Scala” by Chiusano and Bjarnason can be considered the most advanced Scala programming book published so far (in a sense, it can be compared to SICP.). Half of one of my bookshelves is occupied by Scala books, including Scala in Depth, but none of them takes the concept of functional programming as serious as this book, and pushes it to its limits that much. This, in turn, means that most of the Java programmers (including very senior ones), as well as Scala programmers with some experience should prepare themselves to feel very much like a newbie again.
But why the need for such a book, and what’s all that noise about functional programming? Here is my favorite description of functional programming given by Tony Morris : “Supposing a program composed of parts A, B, C, D, and a requirement for program of parts A, B, C, and E. The effort required to construct this program should be proportional to the size of E. The extent to which this is true is the extent to which one achieves the central thesis of Functional Programming. Identifying independent program parts requires very rigorous cognitive discipline and correct concept formation. This can be very (very) difficult after exposure to sloppy thinking habits. Composable programs are easier to reason about. We may (confidentally) determine program behaviour by determining the behaviour of sub-programs -> fewer bugs. Composable programs scale indefinitely, by composing more and more sub-programs. There is no distinction between a ‘small’ and a ‘large’ application; only ‘smaller than’ or ‘greater than’.”
The description above not only points at the core idea of functional programming and why that is important, as well as useful, but also draws attention to the fact that getting used to functional programming design can be difficult for people who are not used to thinking that way. Fortunately, “Functional Programming in Scala” is here to fill a huge void in that respect.
The book can be considered one of its kind, not only because of its strong logical foundations, starting from first principles and rigorously following them to their consequences, but also for its pedagogical approach. Even though it is aimed at practicing programmers and not academics, every chapter includes a lot of exercises arranged in a very nice developmental manner. But make no mistake, this also means that you cannot simply read that book, you can only study it. This, in turn, means that the only way to read the book is to run your favorite Scala coding environment, grab the exercises’ source code (and in case you are stuck, hints, as well as answers) from https://github.com/fpinscala/fpinscala, and start solving the exercise by implementing the required functions and other stubs. Moreover, you should do yourself a favor and also take into account the extra reading at https://github.com/fpinscala/fpinscal....
Depending on your level of Scala, e.g. if you have successfully completed the Coursera course titled “Functional Programming Principles in Scala” by Odersky, you can finish the first few chapters and exercises relatively quickly, but I would suggest to take your time after the first few chapters, 1-2 weeks per chapter will probably be an adequate pace for experienced programmers.
I can recommend this book to serious, curious, brave,and open-minded developers who target JVM by using Scala, and want less duplication, less boilerplate and much more powerful abstractions that are also easier to reason about, and who are ready to invest time to slowly digest the material by doing exercises instead of trying to quickly skim the text.
Bitirir bitirmez yazdığım bir kaç cümlenin üzerinden tekrar geçmek istiyorum. Öncelikle bu kitap bir Scala kitabı değil, Scala ile fonksiyonel programlama kitabı. Scala biliyor olmak kesinlikle gerekli.
İkincisi bu kitap sadece okunarak bir şeyler elde edilecek bir kitap değil. Her bölümde en az 10 adet yapılması gereken çalışma var. Bunları yapmadığınız zaman zaten hem konuyu anlamıyorsunuz hem de sonraki bölümler bu konu ve kavramları devam ettirdiği için takılmaya başlıyorsunuz. Ben açıkcası bu kitabı mayıstan beri günlük egzersiz rutini biçiminde bilgisayardan okuyarak ve favori IDE'mi kullanarak güç bela bitirdim.
Diğer yandan ise fonksiyonel programlamanın gücünü tam olarak görebileceğiniz bir kitap. Neden monad, functor vs yapıları kullanmamız gerektiğini gerçek örneklerden yola çıkarak anlatması takdire şayan.
Kitapla ilgili tek eleştirim ise, aşırı zor olması. Kitap sadece 300 sayfa ama 6 aydır haftada en az 3-4 saat üzerinde çalışarak ve bu süreçte sanırım en az 1000 satır Scala yazarak anca bitirdim. Verilen problemlerin de tabii ki hepsini yapamadım.
Gene de Fonksiyonel Programlama ile ciddi ilgilenen herkesin kesinlikle okuması değil, çalışması gereken bir kitap.
1 1/2 years later I've at least read through the content. I'm still far from done with all the exercises. I'll probably give me another year to do that 😂
The best side of the book is also its worst. It really hammers the content into the head with small steps and repetition in exercises. But this is a time sink. Must people don't have the time. Even I gave up on this book since once, since it was too time consuming.
But the content is worth it and quite illuminating. Even if you probably won't write Scala like that in the near future 😜
Great book that will bring you up to speed with modern functional programming. Knowing Scala is useful but not required. All important concepts like monads, applicative functors and traverses are introduced in natural way as useful solution for common problems. Exercises are well formulated and extremely helpful. Important note: this is NOT the book to learn Scala as language. It's just giving you bare minimum to understand the concepts, not the full power of language.
I've read it all wrong. And I'm the one to be blamed for that.
First: this is not a typical programming language learning book - you don't READ it, you EXERCISE it. Just reading through means that you're getting 10% of knowledge you could get, because every topic covered in the book has its own section of very valuable exercises that will help you master it. And (believe it or not) these exercises are the biggest value addition, much more than the descriptions. Some exercises are really hard and require a lot of time (and understanding of what you just read) - unfortunately I didn't have time for that, but that's something I'll definitely returning to in future.
Second: this book's content is *very* deep, but it's also very theoretical. It's not a bunch of practical examples you'll fly by. Be warned - if requires a given type of mindset and a proper (patient) approach.
Third: this book is still a MEAP (early version). It looks like 99% complete (all the chapters are already there) and I haven't seen any mistakes, but still - it's not a final book.
You have to acknowledge the points above if you're about to read this book. If you accept these, you'll love the book - it's absolutely brilliant. Otherwise, it may still be very valuable, but you won't be able to benefit fully from it.
Btw. if you're new to Scala, this book is not for you.
This book has an outstanding goal – teaching FP principles to those who might have close to no experience with functional programming. I reckon that’s not doable during the coarse of a few hundred pages. Fortunately, this book delivers that what it has promised.
All the book’s materials are split into the chunks of textual information and exercises you’re encouraged to do in order to fully absorb all the meaningful information you might otherwise forget in a day.Since starting to read I understood a lot of concepts that previously I thought of as too complex for me which made my life a lot easier and my code better.
Unfortunately, I’ve found that the most important parts of the book were 5 first chapters as well as 3 last chapters. Besides these chapters I got lost trying to digest some of the concepts that this book has tried to teach me. Apparently that has something to do with the amount of exercises you need to complete to make a progress with this book. I’ve spent more than 2 months in reading and doing the book’s exercises, which was a real exhaustive experience and made me glad that finally I’ve finished this book without abandoning it due to frustration.
My score is 4/5. Authors need to grasp more teaching experience to make their book easier to comprehend and get rid of some useless exercises but keep all the important ones.
I've started rereading this again and was just reminded of one of things I most detest about this book: required exercises. No. I will not do these and if you cannot communicate clearly what you are trying to without these exercises, then I do not believe you have done a good job.
Fantastic book about functional programming in general using the Scala language.
I really liked the way they went through some well chosen examples before introducing higher level abstractions like Monoids, Applicatives and Monads. That really helped to cement the general pattern to look for and how to structure your code to use these abstractions. It helped that the book used Scala which doesn't necessarily include special support for these sort of abstractions, as you got to see how to build them yourself and it didn't gloss over how they worked. Which is sometimes a failing of other Haskell FP material and it's certainly refreshing not to hear about burritos or such nonsense in describing Monads.
I felt that the use of algebras, while interesting and something I'll likely lean on, was a bit vague and not followed through as much as I'd have liked.
Fantastic book, that I'll be coming back to again. I view this more of a FP book rather than a Scala book so I think it has value for people interested in Haskell, OCaml or other FP languages.
Finished the 12 edition. Although I still need to go through it several times to get some of the harder exercises. I fill this book will be a classic.
The first 6 chapters are great to get a mood and idea of Functional Programming and how to do it in Scala. Then you get into real life libraries to get the power of Functional Programming. Chap 10-12 give some of the best explanation for Monoid/Functor/Monad/Applicative Functor/Traversable Chap 13-14 will get you into the "weak" side of Functional Programming, real IO/States. Chap 15 then will show you how to do Streaming Processing (which is really hot topic) with "Machines".
The book though is pretty slow in the sense of showing things, jumping over chapters will not make you lost, but will impair your understanding of abstract concept (as a lot of them can only be understood with multiple concrete examples)
Very good. Well deserved 5 stars for the content. It has many useful concepts distilled and explained. It just shaped and cleared how I think about these concepts. Liked its style very much.
For the kindle version (I read), the formatting is not so good though. The code listings with arrows are hard to read on a first gen paperwhite (without zooming (landscape mode) the text is much less readable than the smallest font type, after zooming it is still not so nice I wish that was a scalable image instead of rasterized).
This is a great book to learn functional programming via Scala. It is not about learning Scala,but functional programming. More importantly it contains tons of exercises. I guess I will keep on doing them for quite a while, since I skipped over many of them.
It makes a great job explaining concepts which seem daunting like monads, referential transparency, effects, etc.
I was programming in Scala for some time, and for me this was really the most adequate moment. I wouldn't recommend it to a beginner, but for deepening you knowledge it is pure (functional) gold.
It was a very challenging book. The material in there is really vast and well prepared with tons of exercises. FP makes you think in a different way, and that's hard to accept at first. After finishing this book I know more about FP but seeing a bigger picture I know there's more to uncover than I initially thought.
I would have given all the stars of the world to this book. Difficult read but a brilliant book I don’t say I have read completely. It takes months or years to get this whole thing. This book is tremendous contribution to “purely” style functional programming. If you wish to learn Haskell I recommended going Scala route and working through this book!!!
This book challenged the way I thought about programming and building software. It forced me to think deeply about FP techniques and the tradeoffs I accept by not using FP. This book deserves a lot of attention. I would not recommend reading through FP in Scala like a book. You should expect to spend a significant amount of time doing exercises and reviewing the example source listings.
This is the fp book I will come back to again and again, I have only finished half of it for now, and It has already improved the thinking and code structures for me... I will come back.
One of the advanced level book I'd recommend. Despite the title, having experience with Scala is not prerequisite of this book. Good book to learn about functional thinking.
If you want to learn pure functional programming, this is the book! No prior FP knowledge needed. All concepts are wonderfully explained. Lots of exercises that MUST NOT be skipped.
This is one of the best book to learn (typed)functional programming. I found it to be even better than some of the books available in Haskell.
- It starts slowly but gets quite dense as it proceeds to the later chapters.
- Learn Building infinite streams using scala constructs! This is quite helpful in understanding laziness. Though I enjoyed building infinite streams in SICP more, the coverage in FP in scala book turned out quite decent.
- The second part builds three very different libraries using FP and discover similar abstractions in each of them. We learn to discover the minimum set of primitive operations required for each of these libraries. We understand that why we need laws for the operations library will support and identifying the minimum set of laws.
- In third part we 'name' the abstractions that we found in the libraries built in part 2.
- One of the best coverage on Monads. This book puts it in words that why it is difficult to understand monads and every time we read them - it feels like - “OK, I thought I understood monads before, but now I really get it.” :). In exercises it then showcases this problem of monads understanding by asking the reader to explain in words what monad operations do in different contexts.
- Exercises are quite decent and an integral part of the book. I found most of the exercises quite approachable and at the right level of difficulty needed to grasp the concept.
- I really appreciate the work for providing the exercises as well as solutions on github and make them available with the required build setup so that any one can compile and execute without much hassle.
- I learned most of the topics covered in the last part: localized effect(using types to make sure effects are local), StreamingIO for the "first time". This gave me an opportunity to see how well I can learn complete new topics from this book. It turns out that apart from some parts of last chapter I was able to follow through without much difficulty. However, I think last chapter could be improved to make it more approachable.
- I am yet to develop my taste buds for Scala syntax. As of now, it does not look clean and perhaps the OOPs part of Scala is to blame. I hope for a similar kind of book in Haskell. Perhaps there is already one that I am not aware of. Well, for this book I can go as far as that if one has to learn Scala only to read this book then so be it!
Don't judge this book by its cover. Or by its slim profile.
This is an extremely in-depth an challenging deep dive into FP, and it's very hands on.
You'll be asked to re-derive and re-implement many features of Scala's standard library... and from first principles.
If you're used to tearing through programming books and learning a language/framework in a weekend.. then this will leave you frustrated. (At least in my experience.)
But if you sit back, do it in your spare time, and treat it as a longterm project -- you'll be slowly rewarded. (That's how I've been approaching it, and it's been relatively painless/pleasant, after a few false starts.)
Also don't be afraid to look online for help. The author provides hints & answers to the exercises on Github, and even following along can be enlightening.
It would also be helpful to work through this as a group, maybe as a class. (If only for the emotional support.)
Love this book. Scala was conceived as a fusion between OO and Functional, and no other book I've read expresses it as well as "the red book".
It's not perfect though, but that's a personal preference. The second part of the book - and to a lesser extent the third too - exposes problems in a non-linear way. This is intentional. The author wants to simulate the somewhat meandering journey of coming up with an API. But to me the dead ends and frequent breaks to write exercises distract from the larger picture. This encumbers skimming the book later for reference. I would have preferred exercises were kept to a minimum from the second part onwards, and preferably at the end of the chapters or major sections. Again, this is probably just personal learning style.
This is my second run through this book, and I'll probably pick it up again in the future.
Haven't finished the book but I found it way too hard for my taste. It could have been renamed "101 scala exercises to practice functional programming with hints".
It might be more useful for someone who's already had real world experience with functional programming or programming with scala, but for someone who's new to these technologies and paradigms, you will not have much to take from it as it will simply go over your head.
Might come back to this book in a few month's time but if you're a beginner like me, just skip this. It will save you some time and effort.