liveBook · Manning

Type-lifting function

As explained in The Joy of JavaScript

A type-lifting function is a constructor-like function that places a raw value into a context or container type.

A type-lifting function places a raw value into a context or container so later operations can preserve that context. For a container type C, the constructor is commonly named C.of or C.unit. section 5.1

A lifted container typically provides:

  • A constructor such as Array.of or C.of that brings a value into the container. section 5.1
  • A map method that transforms the contained data while retaining the container structure. section 5.1
  • An implementation-specific extraction operation, such as Array#pop. section 5.1

Lifting a string into an array

Array.of('aabbcc').map(unique).map(join).map(toUpper).pop() produces 'ABC'. The array supplies the context, map sequences transformations, and pop extracts the result. section 5.1

Array.of('aabbcc')
  .map(unique)
  .map(join)
  .map(toUpper)
  .pop(); // 'ABC'

Inspect the compact Array.of example showing construction, chained mapping, and extraction. section 5.1

How The Joy of JavaScript covers it

How deep it goes
Defines construction, mapping, and extraction, then demonstrates them with arrays without fully specifying wrapper-specific logic.
Examples
Uses Array.of with unique, join, and toUpper to transform "aabbcc" into "ABC".
What you can do after
Apply it via JavaScript containers by lifting values, mapping transformations, and extracting results.
How it connects
Connects type-lifting functions to containers, map, immutable data structures, algebraic data types, and higher-kinded composition.

Also explained in

Compare how 4 books explain type-lifting function →

Related concepts

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