Now that we have learned about the most common FP concepts, it is time to learn about the most common FP techniques and patterns.
FP techniques
Composition
Functional composition is a technique or pattern that allows us to combine multiple functions to create a more complex function.
The following code snippet declares a function used to trim a string and a function used to transform a piece of text in uppercase text:
const trim = (s: string) => s.trim(); const capitalize = (s: string) => s.toUpperCase();
We can create a function that performs both the preceding operations by composing them:
const trimAndCapitalize = (s: string) => capitalize(trim(s));
The variable trimAndCapitalize is a function that invokes...