Chapter 04: Currying

The book uses a function curry to transform a regular function it to something that can be partial applied. Unfortunately, fp-ts does not have an equivalent "auto-curry" function because it's not possible to do so and retain complete types.

You must manually write your functions in curry format:

const match = curry((what, s) => s.match(what));
const replace = curry((what, replacement, s) => s.replace(what, replacement));

Using these functions remains the same; you just lose the flexibility of calling it either way.

Map

const map = curry((f, xs) => xs.map(f));
const getChildren = x => x.childNodes;
const allTheChildren = map(getChildren);

One key difference between the book and fp-ts is that the book uses a single generic map function. In order to maintain type safety, fp-ts provides a specific map functions for each functor.

In the above example, we need to map over an array, so we import fromfp-ts/ReadonlyArray.

Last updated