Книга: Functional Programming in JavaScript
Назад: Type safety
Дальше: Creating functors

Functors

While morphisms are mappings between types, functors are mappings between categories. They can be thought of as functions that lift values out of a container, morph them, and then put them into a new container. The first input is a morphism for the type and the second input is the container.

Note

The type signature for functors looks like this:

// myFunctor :: (a -> b) -> f a -> f b

This says, "give me a function that takes and returns and a box that contains (s), and I'll return a box that contains (s).

Назад: Type safety
Дальше: Creating functors

bsn
thank
Vesa Karvonen
I hope you don't mind, but I’d like to point you and your readers to my high-performance optics library for JavaScript that is in production use in multiple projects, has comprehensive support for partial optics and interactive documentation: https://calmm-js.github.io/partial.lenses/ (this takes a moment to load — be patient!)