Skip to content

Latest commit

 

History

History
30 lines (22 loc) · 1.25 KB

README.md

File metadata and controls

30 lines (22 loc) · 1.25 KB

Build Status Coverage Status npm version

LazyList

LazyList implements map, filter and reduce in JavaScript Arrays with lazy evaluation.

Why?

Because map, filter and reduce operations always return a new Array or depends on previous operations. When working with large lists this can be a problem. What LazyList do is combine all these operations in a single execution, returning only one final Array or result.

Usage

import lazy from 'lazy-list';

const list = [0, 1, 2, 3, 4, 5, 6, 7, 9, 10];
const mapped = lazy(list)
  .filter(v => v > 4)
  .map(v => v * 2);

// filter and map returns a LazyList Object
// use LazyList.value() to get the result
console.log(mapped.value()); // [10, 12, 14, 18, 20]

// LazyList.reduce will execute all previous operations
// and return the result
const sum = mapped.reduce((a, b) => a + b);
console.log(sum); // 74