Jump to ratings and reviews
Rate this book

Functional Programming in C#

Rate this book
Real world examples and practical techniques for functional programming in C# without the jargon and theory.

In Functional Programming in C#, Second Edition you will learn how

Use higher-order functions to reduce duplication and do more with less code
Use pure functions to write code that is easy to test and optimize
Write pleasant APIs that accurately describe your program's behavior
Use dedicated types to handle nullability, system errors, and validation rules predictably and elegantly
Write composable code without the overhead of an IoC container

Functional Programming in C# has helped thousands of developers apply functional thinking to C# code. Its practical examples and spot-on treatment of FP concepts makes it the perfect guide for proficient C# programmers. This second edition is fully revised to cover new functional-inspired features in the most recent releases of C#, including tuples, async streams, pattern matching, and records. Each chapter is packed with awesome perspectives and epiphany moments on how functional programming can change the way you code.

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

About the technology
Turbocharge your C# code. Good functional techniques will improve concurrency, state management, event handling, and maintainability of your software. This book gives you practical answers to why, how, and where to add functional programing into your C# coding practice.

About the book
Functional Programming in C#, Second Edition teaches functional thinking for real-world problems. It reviews the C# language features that allow you to program functionally and through many practical examples shows the power of function composition, data-driven programming, and immutable data structures. All code examples work with .NET 6 and C# 10.

What's inside

Higher-order functions reduce duplication and do more with less code
Code based on pure functions is easy to test and optimize
Write pleasant APIs that accurately describe your program’s behavior
Write a Web API in a functional style
Monadic composition with LINQ

About the reader
For intermediate C# programmers.

About the author
Enrico Buonanno studied Computer Science at Columbia University and has over 15 years of experience as a developer, architect, and trainer.

Table of Contents
PART 1 GETTING STARTED
1 Introducing functional programming
2 Thinking in functions
3 Why function purity matters
PART 2 CORE TECHNIQUES
4 Designing function signatures and types
5 Modeling the possible absence of data
6 Patterns in functional programming
7 Designing programs with function composition
PART 3 FUNCTIONAL DESIGNS
8 Functional error handling
9 Structuring an application with functions
10 Working effectively with multi-argument functions
11 Representing state and change
12 A short introduction to functional data structures
13 Event A functional approach to persistence
PART 4 ADVANCED TECHNIQUES
14 Lazy computations, continuations, and the beauty of monadic composition
15 Stateful programs and stateful computations
16 Working with asynchronous computations
17 Traversable and stacked monads
18 Data streams and the Reactive Extensions
19 An introduction to message-passing concurrency

448 pages, Paperback

Published February 1, 2022

48 people are currently reading
225 people want to read

About the author

Enrico Buonanno

4 books10 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
74 (61%)
4 stars
40 (33%)
3 stars
7 (5%)
2 stars
0 (0%)
1 star
0 (0%)
Displaying 1 - 24 of 24 reviews
Profile Image for Michael.
13 reviews
July 27, 2022
The most useful aspect of this book, in my opinion as a C# programmer, would be the introduction of functional concepts through examples of C#. However, after completing this book I came to the conclusion that C# just isn't the language to perform functional programming in. There are a lot of trials and tribulations that come with attempting to make an object-oriented language perform functional actions, and many of those woes could seemingly be overcome by utilizing a more purpose-driven language like F#, Haskel, or any of the other functional-first languages. There is more than one occasion in which the author mentioned a functional concept that just simply wasn't possible in C#.

If I were to re-write this book (not that I could), I would focus on using idiomatic C# concepts to perform function actions, rather than using more functional concepts. Using `Select` instead of a `Map` function or `SelectMany` rather than `Bind`. While it is mentioned in the books how these concepts are essentially interchangeable, it would simplify my understanding of the concepts if each time I didn't need to perform the translation in my head. It would also be beneficial to use a more established library like `LanguageExt` rather than rolling a custom library (`LaYumba`), which would alleviate some of the tribulations I encountered when attempting to apply these concepts with new vocabulary that didn't match those taught in the author's library.

But on a more uplifting note, I think the book did effectively introduce me to concepts. I found that it didn't give me a deep enough understanding of them that I could effectively use them without much issue (there was a lot of stumbling when I attempted to apply these concepts to a demo application without any handholding). However, it did make me aware of the concepts and help me know what I needed to look up; it gave me a glimpse of the end goal so that I could pave my own way there.

I'm not sure I would recommend this book as a good way to learn a functional language. I think there may be other, better alternatives out there that use C# as a demonstration. However, I don't think I would discourage anyone from trying it and wouldn't try to convince them to pick an alternative if they've already decided on this one. The book was reasonably effective and I cannot fault it for it's ability to introduce concepts.
Profile Image for Sebastian Gebski.
1,190 reviews1,342 followers
September 16, 2017
I've reviewed MEAP 10 version - it seems to contain all the chapters from the final version.

I've got this one as a compensation for cancelled MEAP or something, I didn't really plan to read it as I'm rather reluctant when it comes to OOP lanaguages that try to pretend they are good in FP. Fortunately, I was very pleasantly surprised...

1. Maybe I've just matured that much, but I think that this book contains the most engineer-friendly definition of Monad ever :) What is more, it shows its practicalities & compares Monads to some very similar functional constructs (e.g. applicatives) in very clear AND practical way. But don't expect it to jump into very sophisticated FP theory - it doesn't go significantly further than that (functors, applicatives, traversables, observables, etc.).

2. This book doesn't use any particular FP lib for C#. Everything is being built from scratch, but I don't find it at all as it doesn't really take that much code & it makes all the clarifications much more approachable.

3. There's a very nice chapter about error handling with usage of functional constructs - very well thought & clear. Diagrams were good enough even in the MEAP version I had.

4. Another interesting topic (that has been covered: in chapters 5 & 7) is functional composition in smaller & larger scale. Very few FP book authors approach this topic directly - majority of them focuses on atomic, syntax-level details.

5. I generally rate the final chapters lower (not because they are terrible, but because you can find similar context - e.g. about Rx - in many other sources), but there's one very interesting topic covered there that was really worth waiting for - problem of stacking monads (of different nature) - this is something you (as an FP practitioner) encounter sooner or later, but I haven't seen this covered in any other book.

To summarize: I honestly recommend this book to any C# dev, who'd like to "broaden her/his horizons". If you're into FP, but you're not using C#, don't bother ofc.
And no, no, no - I didn't ask you to go & start implementing all this straight away in your production code :)
Profile Image for Rene Stein.
228 reviews36 followers
October 20, 2019
Hodnocení pro hotovou knihu
======================================
Předběžné hodnocení MEAP verze z 2.8. 2016 - ***
MEAP V 10 - **** (chyby v kapitole 15?)
Profile Image for Wayne Tanner.
5 reviews4 followers
January 16, 2018
This is one of the better programming books I've read in the last couple of years.
Profile Image for Pawel.
6 reviews
May 30, 2018
Really mind-bending! (as one of the reviewers wrote)
It changed the way I see: throwing Exceptions, ifs, static functions, mutability, nulls.
Now I look at "containers" like IEnumerable, Task, Func differently and a lot deeper. It encouraged me to write my own "containers". I see functions (Func) like just any other values.
I also found out why LINQ is so readable - because it is the functional part of C#.

The only weak point of the book are its two last chapters (14, 15). In my opinion they seem like chapters taken from completely different book. But it didn't change the way I see the book.

I highly recommend it!
Profile Image for Jakub Jareš.
1 review1 follower
July 6, 2018
Great content, and overview of some of the functional concepts. But unfortunately I don't see myself using any of the practices any time soon in C#. Unfortunately the author has to fight C# a lot and as a result the code is building on blocks that have overhead associated with it (chaining many Func together), and runs in many different shortcomings of C# generic type inference. Still it is nice to see how some of the problems are solved, and compare solution presented in this book with solutions from other authors, and then with how easy it is to do in a language that was made for functional paradigm.
Profile Image for Guilherme Ferreira.
61 reviews2 followers
February 20, 2018
A very complete guide about functional programming (FP), including some architecture stuff like CQRS, event sourcing and others advanced topics like testing, concurrent and asynchronous programming. All these subjects are addressed using the FP concepts. I recommend this book to C# developers that want to learn how to extract the max from functions, providing a testable and reusable code, FP is much more than LINQ.
Profile Image for Garry Flanagan.
3 reviews1 follower
July 14, 2021
I haven't come across a programming book which was a joy to read and just as informative since "Clean Code" by Robert Cecil.

The explanations, examples and personal reasoning for the use of each talking point was fantastic. It is rare to find a programming book which is detailed and not dry. You can tell your reading a book written by someone with real world experience and less like a book meant a "car manual".
7 reviews
October 27, 2020
The author did a great job of explaining functional concept from an object oriented perspective. He provided lots of examples for each new concept he introduced. The organization and pacing was good too. I am already incorporating these concepts into my code submissions to create more concise and treatable code while minimizing my exposure to bugs.
Profile Image for Andy.
7 reviews5 followers
April 15, 2018
I have been trying to pick up functional programming for a while, but this is the first piece of learning material which has really made it click for me.

The explanations used are really clear, and it builds on simple concepts from start to finish.
Profile Image for Aliaksandr Kulitski.
46 reviews2 followers
September 1, 2018
Очень хорошая книга для погружения из императивного мира в функциональный. Очень понятное объяснение базовых концепций на основе C#. Также поясняются недостатки использования C# в функциональном стиле. Очень мало воды, что очень порадовало. В стиле с применением понятных тулов.
Profile Image for Claus.
89 reviews3 followers
June 8, 2021
Well written and educational for those seeking to improve on their software development skills. I got this as a way to bridge from classical object oriented programming into the world of functional programming. I have read the first half of the book multiple times, but have yet to finish the book.
11 reviews
January 27, 2018
If you are a C# programmer and you want to learn functional programming this is the book you should read.
Profile Image for Rohit.
21 reviews5 followers
April 12, 2018
Just awesome and must read. This book goes to the top of my shelf, Chapter 3 and Chapter 8 are my favorite, it made applicatives, monads and functors super clear.
Profile Image for Chad Miculek.
17 reviews
February 20, 2019
Really changed my style. This is so clearly written. I am reading it a second time, and it is a joy.
Profile Image for Andrei Tarutin.
41 reviews2 followers
February 27, 2022
Quite an impressive book but needs a lot of attention and time to dive into it. It personally took from me about 1 year to complete it consciously.
9 reviews
June 16, 2022
Reading this alongside a Unit Testing book has really improved my code.
Profile Image for Marius Muntean.
3 reviews
May 1, 2022
Excellent book for widening your programming skills!

It is well written and you can follow along really easily. The examples are great and I can immediately think of ways to apply them in my current project.

For me, the main takeaway is that there is a way to write C# code in a way that is terse yet easy to understand, as opposed to writing terse but cryptic code. You do it by preparing a few re-usable functions that then allow you to write boilerplate-free code. And it is exactly that boilerplate-free code that is a delight to read.

Who knows, this might be my jumping board towards that sweet F# salary :D

I'm 2 thirds through the book and I'm already thinking about re-reading it because it is full of nuggets which I don't think I extracted in the first go.
Profile Image for Myte.
16 reviews
September 6, 2022
Nice book that shows you how functional concepts could be used in C#. Show problems and weaknesses of C# as language, used for functional. After this book you may have an interest to look at F# as language, which is functional-first
Profile Image for Matthew Severson.
2 reviews
August 28, 2019
This book has opened my eyes to the world of functional programming and has made me a much better C# developer in the process. The author does a good job of introducing more complex topics and ramping up the complexity slowly throughout the book. This is nice especially when you come from an imperative background. If you are a .NET developer you should buy this book, as it will make you a much better programmer.
Profile Image for Dmitry Dorogoy.
2 reviews
October 10, 2022
As a C# programmer I used LINQ and other stuff and I realize I'm in love with functional programming. My recommendation - this book is highly recommended for ALL C# programmers!
Displaying 1 - 24 of 24 reviews

Can't find what you're looking for?

Get help and learn more about the design.