npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sr-lazy

v0.2.0

Published

Generator for a lazy-evaluated function

Readme

SR_LAZYEVALUATION_JS

const assert = require("assert");
const now = require("performance-now");

const fib = $lazy(n => {
    if (n == 0) {
        return 1;
    }
    if (n == 1) {
        return 1;
    }
    return fib(n - 1) + fib(n - 2);
});

const start = now();
for (let i = 0; i < 1000; i++) {
    fib(i);
}
const performance = now() - start;

assert(performance < 1000);
const sumOf = $lazy((a, b, c, d) => a + b + c + d);

const sumOf_1 = sumOf(1);
const sumOf_2 = sumOf(1, 2);
const sumOf_3 = sumOf(1, 2, 3);

console.log(sumOf_1(10, 11, 12));   //34
console.log(sumOf_2(10, 11));       //24
console.log(sumof_3(10));           //16
const ary = Array(100).fill(0).map((_, i) => i);
const lazyAry = lazy(ary);
const cb = x => x + 1;

const lazyMap_start = now();
for (let i = 0; i < 1000000; i++) {
    lazyAry.map(cb).toArray();
}
const lazyMap_performance = now() - lazyMap_start;

const map_start = now();
for (let i = 0; i < 1000000; i++) {
    ary.map(cb);
}
const map_performance = now() - map_start;

assert(lazyMap_performance * 5 < map_performance);

How to instal

> npm install sr-lazy

What's this

this package give you lazy function and binding function.

Lazy for function

Lazy needs a function as a pure function.

lazy

sample

const add = lazy((x, y) => x + y);
const add10 = add(10);  // not evaluated
const res = add10(20);  // not evaluated
console.log(res());     // evaluated
console.log(res());     // read from chache

$lazy

sample

const add = $lazy((x, y) => x + y);
const add10 = add(10);  // not evaluated
console.log(add10(20)); // evaluated
console.log(add10(20)); // read from chache

sample

Each mapper ( mapper(1), mapper(2), mapper(3), mapper(4) ) will calls only once.

const ary = [1, 1, 1, 1, 2, 2, 2, 3, 3, 4];
const mapper = $lazy(v => v + 1);
ary.map(mapper);

Lazy for Array

const ary =
    lazy([1, 2, 3])             // create lazy array
    .map($lazy(x => x + 1))     // not evaluated
    .map($lazy(x => x + 1));    // not evaluated
console.log(ary.$toArray());    // evaluted

map

map : ( any -> any ) -> Lazy(Array)

const ary =
    lazy([1, 2, 3])
    .map($lazy(x => x + 1));
console.log(ary.$toArray()); // [2, 3, 4]

filter

filter : ( any -> Boolean ) -> Lazy(Array)

const ary = lazy([1, 2, 3, 4, 5, 6])
    .filter($lazy(x => x < 4));
console.log(ary.$toArray());    // [1, 2, 3]

flatten

flatten : () -> Lazy(Array)

const ary = lazy([1, 2, [3, 4, [5]], 6])
                .flatten();
console.log(ary.$toArray());    // [1, 2, 3, 4, 5, 6]