liveBook · Manning

Wrapper

As explained in Functional Programming in JavaScript

A container type that encapsulates a value so it can be transformed through mapped functions while remaining inaccessible directly.

A Wrapper places a value inside a safety container. Direct access is unavailable; functions transform the contained value through mapping, preserving a controlled boundary around potentially unsafe data. section 5.2

Transforming a wrapped value

const two = wrap(2);\nconst five = two.fmap(plus3); // Wrapper(5)\nfive.map(R.identity); // 5\n\ntwo.fmap(plus3).fmap(plus10); // Wrapper(15)\n\nUse fmap to transform while keeping the value wrapped; use map with the identity function to extract it.

How Functional Programming in JavaScript covers it

How deep it goes
Defines Wrapper, map, fmap, and chaining with JavaScript examples, but stops short of advanced functional data types.
Examples
Demonstrates wrapped strings, null values, incremented numbers, chained transformations, logging, and identity-based extraction.
What it assumes
Assumes basic JavaScript functions, array map, and the identity function while introducing wrappers and functor-style mapping.
What you can do after
Apply it via Wrapper's map and fmap methods to transform values, chain operations, and extract results with identity.
How it connects
Connects wrappers to functors, map, identity functions, referential transparency, and functional error handling.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Programming in JavaScript. The section links point to the parts of the book it draws on.