liveBook · Manning

Identity function

As explained in Functional Programming in JavaScript

A function that returns its argument unchanged.

An identity function returns the argument it receives without changing it. In functional programs, it acts as a simple building block for passing values through higher-order functions and combinators. section 4.6

A function that changes nothing

The identity function has the shape identity :: (a) -> a: it accepts a value and returns that same value. This makes it useful when point-free code needs a function argument, when testing combinator flow, or when extracting data from an encapsulated type. section 4.6

identity :: (a) -> a

Use the type signature to recognize that the input and output have the same role and value. section 4.6

How Functional Programming in JavaScript covers it

How deep it goes
Defines the unchanged return behavior and lists practical uses without developing an implementation or mathematical treatment.
Examples
Uses the identity signature, point-free function arguments, combinator unit tests, and functional data extraction as examples.
What you can do after
Apply it as a neutral function argument and use it to test functional composition or combinator flow.
How it connects
Connects identity with higher-order functions, function combinators, point-free code, composition, and encapsulated types.

Also explained in

Compare how 3 books explain identity function →

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.