Functional Programming in TypeScript
This book is 80% complete
Last updated on 2020-01-17
About the Book
The First installment is Published. Everything is built bottom-up so there is no dependency on the upcoming second installment. The second installment will contain the Monads and the comonads.
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
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
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), EPUB (for phones and tablets) and MOBI (for 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.