Chapter 8, Connecting Functions – Pipelining, Composition, and More
8.1 Headline capitalization: We can make use of several functional equivalents of different methods, such as split()
, map()
, and join()
. Using demethodize()
from Chapter 6, Producing Functions, and flipTwo()
from Chapter 7, Transforming Functions, would have also been possible:
const split = (str: string) => (text: string) => text.split(str); const map = (fn: (x: string) => string) => (arr: string[]) => arr.map(fn); const firstToUpper = (word: string): string => word[0].toUpperCase() + word.substring(1).toLowerCase(); const join = (str: string) => (arr: string[]) => arr.join(str); const headline = pipeline( split(" "), map(firstToUpper), join(" ") );
The pipeline works as expected: we split the string into words, we map each word to make its first letter...