or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-lodash--identity

The modern build of lodash's identity utility function exported as a standalone module.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/lodash.identity@3.0.x

To install, run

npx @tessl/cli install tessl/npm-lodash--identity@3.0.0

index.mddocs/

Lodash Identity

Lodash Identity provides the identity utility function from the lodash library as a standalone Node.js module. The identity function is a fundamental utility that returns its first argument unchanged, making it essential for functional programming patterns, default callbacks, and placeholder operations.

Package Information

  • Package Name: lodash.identity
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install lodash.identity

Core Imports

const identity = require('lodash.identity');

ESM:

import identity from 'lodash.identity';

Basic Usage

const identity = require('lodash.identity');

// Basic usage - returns the input unchanged
const value = identity(42);
console.log(value); // => 42

const object = { a: 1, b: 2 };
console.log(identity(object) === object); // => true

// Common usage as a default callback
const users = [
  { name: 'Alice', active: true },
  { name: 'Bob', active: false },
  { name: 'Charlie', active: true }
];

// Use as default transformation function - filter truthy values
const activeUsers = users.filter(user => user.active);

// Use in array operations where no transformation is needed
const numbers = [1, 2, 3];
const sameNumbers = numbers.map(identity);
console.log(numbers === sameNumbers); // => false (different array, same values)

Capabilities

Identity Function

Returns the first argument it receives unchanged. This function is commonly used as a default transformation function in functional programming patterns and as a placeholder when no transformation is needed.

/**
 * This method returns the first argument it receives.
 * 
 * @param {*} value - Any value of any type
 * @returns {*} Returns the input value unchanged
 * @since 0.1.0 
 */
function identity(value);

Parameters:

  • value (*): Any value - can be any JavaScript type including primitives, objects, arrays, functions, etc.

Returns:

  • (*): Returns the exact same value that was passed in, with no modifications

Usage Examples:

const identity = require('lodash.identity');

// With primitives
identity(1); // => 1
identity('hello'); // => 'hello'
identity(true); // => true

// With objects (returns same reference)
const obj = { name: 'test' };
identity(obj) === obj; // => true

// With arrays (returns same reference)
const arr = [1, 2, 3];
identity(arr) === arr; // => true

// With functions
const fn = () => 'hello';
identity(fn) === fn; // => true

// Common functional programming patterns
const data = [1, 2, 3];

// As a default callback
const transformed = data.map(identity); // [1, 2, 3]

// In filter operations (truthy values)
const values = [1, 0, 'hello', '', true, false];
const truthyValues = values.filter(identity); // [1, 'hello', true]

// As a default transformation in higher-order functions
function processData(data, transform = identity) {
  return data.map(transform);
}

processData([1, 2, 3]); // [1, 2, 3] (no transformation)
processData([1, 2, 3], x => x * 2); // [2, 4, 6] (with transformation)

Typical Use Cases:

  1. Default callback function: When a function accepts an optional transformation callback
  2. Functional composition: As a neutral element in function composition
  3. Array operations: When you need to maintain array structure without transformation
  4. Filter operations: To filter truthy values from arrays
  5. Placeholder function: When an API requires a function but no operation is needed
  6. Type preservation: In generic functions where the input type should be preserved