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

Array Methods in Point-Free Style

Using built-in methods like map, filter, and reduce without wrapping callbacks in arrow functions.

Array Methods in Point-Free Style

You'll learn how to use JavaScript's built-in array methods without explicitly writing callback functions, making your code cleaner and more declarative.

The Core Idea

When you use methods like map, filter, and reduce, you typically pass an arrow function that transforms or tests each element. But if you already have a named function that does exactly what you need, you can pass it directly as the callback—no arrow function wrapper required. This is point-free style applied to array methods: let the function name speak for itself.

Why This Works

Array methods expect callbacks with specific signatures:

  • map(callback) passes (element, index, array) to your callback
  • filter(callback) does the same
  • reduce(callback, initial) passes (accumulator, element, index, array)

If your function matches that signature (or at least accepts the first parameter), you can pass it directly by name.

Examples

// Instead of:
const doubled = numbers.map(n => double(n));

// Point-free:
const doubled = numbers.map(double);

// Instead of:
const evens = numbers.filter(x => isEven(x));

// Point-free:
const evens = numbers.filter(isEven);

// Instead of:
const total = numbers.reduce((acc, n) => add(acc, n), 0);

// Point-free:
const total = numbers.reduce(add, 0);

Think of it like giving directions: instead of saying "for each house, take the house and paint it blue," you just say "for each house, paint blue." The method already knows to pass the house to your painting function.

Key Takeaway: When using map, filter, reduce, and similar methods, pass existing functions directly by name instead of wrapping them in arrow functions—if they match the callback signature, point-free style makes your code more concise and readable.