Practical functional C#

Retired

This book is no longer available for sale.

Practical functional C#

A practical guide to the language-ext C# functional Library

About the Book

This book is focused on the practical use of language-ext functional library in C#. We will break down the Sample projects and see where functional programming fits in modern Web Application development using Asp.Net Core and Domain Driven Design .

dotnetfiddle:https://dotnetfiddle.net/Authors/120678/dimitrispapadim

Github : https://github.com/dimitris-papadimitriou-chr/Practical-Functional-CSharp

This is a substantial Reduction of the book "Functional Programming in C#with Categories"

About the Author

dimitris papadimitriou
dimitris papadimitriou

I have more than 14 years’ experience as full stack developer and Architect.

I Like to stay in touch with all the latest developments in the field, as well as the foundational Theoretical Computer science and algorithm Analysis and Design

https://www.linkedin.com/in/dimitrispapadimitriou/

Table of Contents

  • 1 Language Functional support
    • 1.1 Pure functions and Side effects ... 5
    • 1.2 Evolution of Delegates in C# ... 8
    • 1.3 Higher-Order Functions /Functions as Data ... 11
    • 1.4 Named parameters and Tuples ... 12
    • 1.4.1 Lambda expressions and tuples ... 14
    • 1.5 Extension Methods ... 16
    • 1.6 Using static directive ... 17
    • 1.7 LINQ support for custom Data structures ... 19
    • 1.8 Currying and partial application ... 19
    • 1.9 The language-ext C# library ... 21
    • 1.9.1 Void is not a real type ... 21
    • 1.9.2 Immutable record types ... 22
  • 2 Functors
    • 2.1 The Identity Functor ... 23
    • 2.2 Which Map methods qualify as Valid ... 24
    • 2.3 List Functor ... 25
    • 2.4 Pattern Matching ... 25
    • 2.5 Folds ... 29
    • 2.5.1 The Basic Functor Mechanics ... 32
    • 2.6 Extending Task to Functor ... 33
    • 2.7 LINQ Native Query syntax: Functor Support ... 34
    • 2.7.1 Using the Linq syntax with Task ... 35
    • 2.8 Maybe Functor aka Option ... 36
    • 2.8.1 Dealing with null ... 36
    • 2.8.2 The Null Object Design pattern ... 36
    • 2.8.3 The Functional equivalent - Maybe as Functor ... 37
    • 2.8.4 Maybe Functor Example ... 40
    • 2.8.5 Maybe in Language-ext / Option ... 41
    • 2.8.6 Maybe Functor Example With language-ext Option ... 42
    • 2.8.7 Folding Maybe ... 43
    • 2.8.8 Using the Linq syntax ... 43
    • 2.9 Either Functor ... 44
    • 2.9.1 Pattern matching for Either ... 45
    • 2.9.2 Using C# 8.0 pattern matching ... 46
    • 2.9.3 Either Functor Example ... 46
    • 2.9.4 Either in Language-ext ... 47
    • 2.9.5 Using Either for exception handling ... 48
    • 2.10 Explicitly Compositing Functor ... 51
    • 2.11 Combining Task and Option – Task> ... 53
    • 2.12 Combining Task and Option – OptionAsync ... 55
    • 2.13 Combining Task and Either – Task> ... 56
    • 2.14 Combining Task and Either – EitherAsync<> ... 58
  • 3 Monads
    • 3.1 The List as a Monad ... 62
    • 3.2 The Identity Monad ... 63
    • 3.3 Maybe Monad ... 64
    • 3.3.1 Using language-ext Option ... 66
    • 3.3.2 Using the LINQ syntax with Option Monad ... 67
    • 3.4 Either Monad ... 68
    • 3.4.1 Using Either Monad for exception handling ... 68
    • 3.4.2 Using language-ext Either ... 69
    • 3.4.3 Using the LINQ syntax with Either Monad ... 70
    • 3.4.4 Using Either for Validation ... 71
    • 3.5 Validation Monad ... 71
    • 3.5.1 Using Validation.Apply to Collect validations ... 72
    • 3.5.2 Conversion Between Either and Validation ... 72
    • 3.6 Task as Monad ... 72
    • 3.7 The Task - Option Monad Combination -Task> ... 73
    • 3.8 The Task - Option Monad Combination -OptionAsync<> ... 75
    • 3.9 The Task - Either Monad Combination -Task> ... 77
    • 3.10 The Task - Either Monad Combination -EitherAsync<> ... 79
  • 4 A Clean Functional Architecture Example
    • 4.1 Download and Setup the Project ... 81
    • 4.2 Evolution of Software Architecture ... 81
    • 4.2.1 Layered Architecture ... 82
    • 4.2.2 Clean Architecture with .NET core ... 82
    • 4.3 A Functional Applications Architecture ... 83
    • 4.4 The Contoso Clean Architecture with .NET core and language-ext ... 84
    • 4.4.1 A list of Patterns and Practices ... 85
    • 4.5 Web Api ... 85
    • 4.6 Domain Model ... 87
    • 4.6.1 Repositories ... 89
    • 4.7 CQRS ... 90
    • 4.8 CQRS and MediatR ... 92
    • 4.8.1 The Command Pattern with a Mediator ... 92
    • 4.8.2 Query Workflow ... 95
    • 4.8.3 Command Workflow ... 98

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $14 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub