-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
TypeScript 5 Design Patterns and Best Practices - Second Edition
By :
This section takes a deeper look into some of the most practical and widely used functional structures: functors, applicatives, semigroups, monoids, and traversables. These structures provide elegant solutions to common problems and offer a nice way of thinking about code composition and data manipulation in a more principled way while adhering to functional programming principles. Let’s start with functors.
Functors are a fundamental concept in functional programming that provide a way to apply functions to values wrapped inside a context. They use a mapping operation to apply a function to all values transforming the contents to a new instance of a functor without changing its own structure.
Let’s start by defining a custom functor for a simple container of the Box type:
functional-structures.ts
class Box<T> {
constructor(private value: T) {}
map<...