Skip to content
Carlos De Dios edited this page Oct 21, 2015 · 3 revisions

Description

Function whose only purpose is to return the same provided value.

Note

In the Identity module, there are 2 functions, identity and id, they're the exact same id is simply a shorter version.

Example

/* Regular Approach*/

let v = getRandomValue();
let oddAction = (n) => n * 2;

return v % 2 == 0 ? v : oddAction(v);

/* Identity Approach */

import { identity } from "functional-programming-utilities";

let v = getRandomValue();
let oddAction = (n) => n * 2;

return (v % 2 === 0 ? identity  : oddAction)(v);

This isn't the best example, but there's probably no best example, since Identity simply returns whatever you throw at him.

Clone this wiki locally