need not be of the same type as the original value.
What is a functor?
Thai Pangsakulyanont
30710

A functor is a mapping between categories, meaning that it can map from type a to type b, e.g., a could be a string that maps to a boolean in b, but to satisfy the functor laws, it must maintain its structure after the mapping. In other words, you can’t map from F a to b. You have to map from F a to F b.

So, even though a can be strings and b can be booleans, F from F a and F from F b are still both members of the same functor category.

The blog post author explains:

“In the case of JavaScript, filter is a functor because it returns an Array, however forEach is not a functor because it returns undefined. ie. forEach does not maintain structure.”

He also goes on to explain the functor laws, identity and composition, thus, the examples in “what’s not a functor” hold.

Show your support

Clapping shows how much you appreciated Eric Elliott’s story.