Skip to Content
Mastering JavaScript Functional Programming - Second Edition
book

Mastering JavaScript Functional Programming - Second Edition

by Federico Kereki
January 2020
Intermediate to advanced
470 pages
11h 13m
English
Packt Publishing
Content preview from Mastering JavaScript Functional Programming - Second Edition

Enhancing our container – functors

We want to have wrapped values, so what exactly should return the map() method? If we want to be able to chain operations, then the only logical answer is that it should return a new wrapped object. In true functional style, when we apply a mapping to a wrapped value, the result will be another wrapped value that we can keep working on. 

Instead of map(), this operation is sometimes called fmap(), standing for functorial map. The rationale for the name change was to avoid expanding the meaning of map(). However, since we are working in a language that supports reusing the name, we can keep it.

We can extend our Container class to implement this change and get ourselves an enhanced container: a functor. The ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering JavaScript Functional Programming

Mastering JavaScript Functional Programming

Federico Kereki

Publisher Resources

ISBN: 9781839213069Supplemental Content