liveBook · Manning

Lodash

As explained in Functional Programming in JavaScript

A JavaScript utility library that provides functions for common programming tasks, including collection and object operations.

Lodash is a JavaScript utility library for processing collections and objects with reusable functional operations. It replaces many manual loops with concise, declarative code and exposes its functions through the global _ object. section 3.0 section 3.3

Use Lodash’s core collection operations to transform, combine, and select data:

  • Use _.map to apply a function to every element and return an equally sized array. section 3.3
  • Use reduce to accumulate a collection into one result, such as country counts. section 3.3
  • Use filter with a predicate to keep only elements satisfying a condition. section 3.3
  • Chain operations with _(data).map(...).reduce(...) to separate data transformation from control flow. section 3.0 section 3.3

Select and transform people

const bornIn1903 = person => person.birthYear === 1903; _(persons) .filter(bornIn1903) .map(person => person.fullname) .join(' and '); // 'John von Neumann and Alonzo Church' The filter selects matching records, map extracts their names, and join formats the result. section 3.3

const p1 = new Person('Haskell', 'Curry', '111-11-1111');
p1.address = new Address('US');
p1.birthYear = 1900;

const p2 = new Person('Barkley', 'Rosser', '222-22-2222');
p2.address = new Address('Greece');
p2.birthYear = 1907;

const p3 = new Person('John', 'von Neumann', '333-33-3333');
p3.address = new Address('Hungary');
p3.birthYear = 1903;

const p4 = new Person('Alonzo', 'Church', '444-44-4444');
p4.address = new Address('US');
p4.birthYear = 1903;

Browse the person and address fixtures used to demonstrate Lodash collection transformations and statistics. section 3.3

How Functional Programming in JavaScript covers it

How deep it goes
Defines map, reduce, and filter, demonstrates chains and statistics, and defers performance enhancements to later treatment.
Examples
Demonstrates student-name extraction, person filtering, country counts, and chained map-reduce statistics.
What it assumes
Assumes basic JavaScript and higher-order functions while introducing practical functional operations incrementally.
What you can do after
Apply it via Lodash to write concise collection transformations and declarative pipelines.
How it connects
Connects functional programming with higher-order functions, map, reduce, filter, recursion, and function chaining.

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.