Functional Programming in TypeScript
Functional Programming in TypeScript
About the Book
This book has been retired temporarily, to be improved. It will be resumed at January 2023.
A Paperback version is now Available in Amazon - Functional Programming in TypeScript
This book goes beyond the introductory ideas of functional programming, while progressively building on practical examples in a comprehensive manner. Each example is accompanied by an online autonomous fiddle TypeScript code [ https://codesandbox.io/u/dimitris-papadimitriou-chr/sandboxes], which you can run fork and modify, in order to deepen your understanding of each section.
What you will learn:
- Go beyond the Array.map by understanding how to generalize the idea of map to Functors like Maybe, Either and Promises, etc.
- Go beyond the idea of Array.reduce by understanding the concepts of fold and catamorphism over data structures.
- Learn how to combine functional ideas in order to solve practical problems.
- Use Monads like Maybe, Either, IO, Continuations, and Promises to chain computations.
- Get a deep understanding of recursive methods and learn how to define recursive methods on algebraic data structures.
1.1 Categories 10
- 1.2 Essential Lambda calculus with Js 12
- 1.3 SKI combinators 13
- 1.4 Minimum Type theory 15
- 1.5 String Diagrams 15
2 The Pillars 18
- 2.1 Monoids 18
- 2.1.1 Function composition as a monoid 21
- 2.1.2 Composing monoids 25
- 2.1.3 Folding monoids 23
- 2.2 folding functions under composition 25
- 2.2.1 Monoid homomorphisms and Parallelism 27
- 2.3 Higher order functions 30
- 2.3.1 Strategy pattern 30
- 2.4 Currying and partial application 32
3 Algebraic Data Types 37
- 3.1 The product structure: 37
- 3.1.1 Introduction / Elimination 39
- 3.2 The co-product structure: 40
- 3.2.1 Introduction / Elimination 42
- 3.3 One 43
- 3.4 Recursive Algebraic Types 44
- 3.4.1 On the value of the symbolic representation 45
- 3.5 Extending Union Types 47
- 3.5.1 Adding pattern matching 47
4 Functors 49
- 4.1 The Identity Functor 49
- 4.2 Commutative Diagrams 50
- 4.3 The Functor Laws 51
- 4.4 Extending Promise as Functor 53
- 4.4.1 The Promise - functor laws 53
- 4.5 IO Functor, a Lazy Id Functor 54
- 4.5.1 Thunks 54
- 4.5.2 IO Functor 55
- 4.6 Reader Functor 56
- 4.7 Maybe Functor 58
- 4.7.0 Dealing with null - Null object Design pattern 58
- 4.7.1 The Null Object Design pattern 58
- 4.7.2 The Functional equivalent - Maybe as Functor 59
- 4.8 Either Functor 60
- 4.9 Either for exception handling 61
- 4.1 functors from Algebraic Data types 64
- 4.11 Functor Composition 66
- 4.12 Applicative Functor 68
- 4.13 Reader Applicative Functor 69
- 4.14 Composing Applicatives 71
- 4.15 Decorator design pattern functional idiom with functor 72
5 An Introduction to Catamorphisms 74
- 5.1 Catamorphisms 74
- 5.1.1 Union types cata 75
- 5.1.2 Recursive types cata 76
- 5.2 Catamorphisms through the Visitor Design pattern 77
- 5.2.1 Extending Union Types: Using cata 78
- 5.3 Folds 78
6 Traversable 79
- 6.1 Traversable Array with Either applicative for validation 81
- 6.2 Traversable Algebraic data structures 82
- 6.3 Identity Traversable 83
- 6.4 Applicative Reader Isomorphism with the Interpreter Design pattern 83
- 6.5 Composing Traversables 86
- 6.6 Foldable 86
- 6.6.1 FoldMap 88
- 6.6.2 filter 88
- 6.6.3 Mixins 88
- 6.6.4 Composing Foldables 89
- 6.6.5 Iterators 90
- 6.1 Maybe Monad ... 105
- 6.2 Either Monad ... 108
- 6.2.1 Natural Transformation Between Maybe and Either ... 109
- 6.2.2 Using Either Monad exception handling ... 110
- 6.3 Promise as a Monad ... 112
- Dissecting the Promise.then method 112 ...
- 6.3.1 The then as a monadic Bind ... 113
- 6.4 Combining Promises and Either ... 118
- 6.5 Combining Promises and Either - Example ... 119
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...
80% Royalties. Earn $16 on a $20 book.
We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $12 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.