Functional Programming in C#
How to write better C# code
Enrico Buonanno
- 408 pagine
- English
- ePUB (disponibile sull'app)
- Disponibile su iOS e Android
Functional Programming in C#
How to write better C# code
Enrico Buonanno
Informazioni sul libro
Summary Functional Programming in C# teaches you to apply functional thinking to real-world problems using the C# language. The book, with its many practical examples, is written for proficient C# programmers with no prior FP experience. It will give you an awesome new perspective.Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications. About the Technology Functional programming changes the way you think about code. For C# developers, FP techniques can greatly improve state management, concurrency, event handling, and long-term code maintenance. And C# offers the flexibility that allows you to benefit fully from the application of functional techniques. This book gives you the awesome power of a new perspective. About the Book Functional Programming in C# teaches you to apply functional thinking to real-world problems using the C# language. You'll start by learning the principles of functional programming and the language features that allow you to program functionally. As you explore the many practical examples, you'll learn the power of function composition, data flow programming, immutable data structures, and monadic composition with LINQ. What's Inside
- Write readable, team-friendly code
- Master async and data streams
- Radically improve error handling
- Event sourcing and other FP patterns
About the Reader Written for proficient C# programmers with no prior FP experience. About the Author Enrico Buonanno studied computer science at Columbia University and has 15 years of experience as a developer, architect, and trainer. Table of Contents
PART 1 - CORE CONCEPTS
- Introducing functional programming
- Why function purity matters
- Designing function signatures and types
- Patterns in functional programming
- Designing programs with function composition
PART 2 - BECOMING FUNCTIONAL
- Functional error handling
- Structuring an application with functions
- Working effectively with multi-argument functions
- Thinking about data functionally
- Event sourcing: a functional approach to persistence
PART 3 - ADVANCED TECHNIQUES
- Lazy computations, continuations, and the beauty of monadic composition
- Stateful programs and stateful computations
- Working with asynchronous computations
- Data streams and the Reactive Extensions
- An introduction to message-passing concurrency
Domande frequenti
Informazioni
Part 1. Core concepts
Chapter 1. Introducing functional programming
- Benefits and tenets of functional programming
- Functional features of the C# language
- Representation of functions in C#
- Higher-order functions
1.1. What is this thing called functional programming?
- Functions as first-class values
- Avoiding state mutation
1.1.1. Functions as first-class values
1A REPL is a command-line interface allowing you to experiment with the language by typing in statements and getting immediate feedback. If you use Visual Studio, you can start the REPL by going to View > Other Windows > C# Interactive. On Mono, you can use the csharp command. There are also several other utilities that allow you to run C# snippets interactively, some even in the browser.
Func<int, int> triple = x => x * 3; var range = Enumerable.Range(1, 3); var triples = range.Select(triple); triples // => [3, 6, 9]
1.1.2. Avoiding state mutation
int[] nums = { 1, 2, 3 }; nums[0] = 7; nums // => [7, 2, 3]
Listing 1.1. Functional approach: Where and OrderBy don’t affect the original list
Listing 1.2. Nonfunctional approach: List<T>.Sort sorts the list in place
var original = new List<int> { 5, 7, 1 }; original.Sort(); original // => [1, 5, 7]