Course contentsShow
← JavaScript
Lesson 1773 of 2,72337. Functional Programming PatternsFree lesson

Currying in Array Methods

Combine currying with map/filter to create reusable transformation pipelines.

Currying in Array Methods

You'll learn how to combine currying with map, filter, and other array methods to build flexible, reusable transformation pipelines.

The Core Idea

Currying shines when paired with array methods. Instead of writing inline callbacks or repeating logic, you create curried functions that return specialized transformers. These can be plugged directly into map, filter, or reduce, making your data transformations composable and declarative.

Think of it like building with LEGO blocks: curried functions are pre-shaped pieces you snap together instead of sculpting each piece from scratch every time.

How It Works

// A curried operation
const multiply = factor => number => number * factor;

// Create reusable transformers
const double = multiply(2);
const triple = multiply(3);

const numbers = [1, 2, 3, 4];

numbers.map(double);  // [2, 4, 6, 8]
numbers.map(triple);  // [3, 6, 9, 12]

With filter:

const hasProperty = prop => obj => prop in obj;
const hasMinValue = (prop, min) => obj => obj[prop] >= min;

const users = [
  { name: 'Alice', age: 25 },
  { name: 'Bob', age: 17 },
  { name: 'Carol', age: 30 }
];

users.filter(hasProperty('age'));  // All three
users.filter(hasMinValue('age', 18));  // Alice, Carol

Why This Matters

Instead of users.filter(u => u.age >= 18) scattered throughout your code, you define isAdult = hasMinValue('age', 18) once and reuse it everywhere. Your intent is clear, your code stays DRY, and you can test the logic in isolation.

Key Takeaway: Currying transforms array callbacks into reusable, named functions—turning procedural loops into declarative pipelines you can compose, test, and maintain effortlessly.