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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@critocrito/curry

v0.3.1

Published

Curry functions with a name.

Downloads

6

Readme

curry

Curry functions with a name.

Synopsis

License: GPL v3 npm version Build Status Coverage Status

These are curry functions that also set the name of the curried functions. This improves the usability of using those curried functions in the REPL.

Installation

npm install @critocrito/curry

Usage

import {curry2} from "@critocrito/curry";

const sum2 = curry2("sum2", (a, b) => a + b);
console.log(sum2); // [Function: sum2-2]
console.log(sum2(1)); // [Function: sum2-1]
console.log(sum2(1, 1)); // 2
console.log(sum2(1)(1)); // 2

API

The module exports curry functions for an arity up to 10.

  • curry2
  • curry3
  • curry4
  • curry5
  • curry6
  • curry7
  • curry8
  • curry9
  • curry10
import {curry5, curry10} from "@critocrito/curry";

const sum = xs => xs.reduce((memo, i) => memo + i, 0);

const sum5 = curry5("sum5", sum);
const sum10 = curry10("sum10", sum);

sum5(1, 2, 3, 4, 5); // 15
sum10(1, 2, 3)(4, 5)(6, 7, 8, 9, 10); // 45

All curry functions are created using the ncurry factory. If the provided arities are not sufficient, create a new one.

import {ncurry} from "@critocrito/ncurry"

const sum = xs => xs.reduce((memo, i) => memo + i, 0);
const curry15 = ncurry(15);

const sum15 = curry15("sum15", sum);

Performance

When applying all arguments to the curried function at once, e.g. curriedSum(1, 2, 3, 4, 5) the implementation of Lodash is faster.

lodash full application with 2 arguments x 3,713,955 ops/sec ±2.23% (82 runs sampled)
this curry full application with 2 arguments x 1,246,646 ops/sec ±2.42% (79 runs sampled)
lodash full application with 3 arguments x 2,635,956 ops/sec ±1.84% (81 runs sampled)
this curry full application with 3 arguments x 1,141,811 ops/sec ±2.34% (82 runs sampled)
lodash full application with 4 arguments x 2,290,952 ops/sec ±2.61% (83 runs sampled)
this curry full application with 4 arguments x 1,037,962 ops/sec ±2.84% (84 runs sampled)
lodash full application with 5 arguments x 2,015,086 ops/sec ±1.91% (81 runs sampled)
this curry full application with 5 arguments x 946,800 ops/sec ±2.24% (85 runs sampled)
lodash full application with 6 arguments x 1,800,830 ops/sec ±2.30% (83 runs sampled)
this curry full application with 6 arguments x 896,425 ops/sec ±1.84% (85 runs sampled)
lodash full application with 7 arguments x 1,670,538 ops/sec ±2.36% (83 runs sampled)
this curry full application with 7 arguments x 818,076 ops/sec ±2.06% (84 runs sampled)
lodash full application with 8 arguments x 1,525,016 ops/sec ±3.06% (83 runs sampled)
this curry full application with 8 arguments x 773,187 ops/sec ±1.54% (85 runs sampled)
lodash full application with 9 arguments x 1,390,510 ops/sec ±2.88% (78 runs sampled)
this curry full application with 9 arguments x 731,658 ops/sec ±1.77% (85 runs sampled)
lodash full application with 10 arguments x 1,376,320 ops/sec ±2.33% (84 runs sampled)
this curry full application with 10 arguments x 693,727 ops/sec ±2.54% (83 runs sampled)

But when actually applying arguments incrementally (which is the point of a curried function), e.g. curriedSum(1)(2)(3)(4)(5), this implementation performs better than Lodash.

lodash piecemeal application with 2 arguments x 269,906 ops/sec ±1.22% (84 runs sampled)
this curry piecemeal application with 2 arguments x 293,983 ops/sec ±5.06% (77 runs sampled)
lodash piecemeal application with 3 arguments x 141,272 ops/sec ±1.32% (86 runs sampled)
this curry piecemeal application with 3 arguments x 172,166 ops/sec ±4.27% (80 runs sampled)
lodash piecemeal application with 4 arguments x 93,988 ops/sec ±2.19% (83 runs sampled)
this curry piecemeal application with 4 arguments x 118,644 ops/sec ±4.62% (79 runs sampled)
lodash piecemeal application with 5 arguments x 69,943 ops/sec ±5.81% (88 runs sampled)
this curry piecemeal application with 5 arguments x 89,667 ops/sec ±4.71% (77 runs sampled)
lodash piecemeal application with 6 arguments x 57,978 ops/sec ±0.99% (86 runs sampled)
this curry piecemeal application with 6 arguments x 72,254 ops/sec ±4.49% (77 runs sampled)
lodash piecemeal application with 7 arguments x 47,702 ops/sec ±1.32% (83 runs sampled)
this curry piecemeal application with 7 arguments x 61,147 ops/sec ±4.31% (79 runs sampled)
lodash piecemeal application with 8 arguments x 40,564 ops/sec ±2.14% (90 runs sampled)
this curry piecemeal application with 8 arguments x 52,434 ops/sec ±4.35% (82 runs sampled)
lodash piecemeal application with 9 arguments x 34,938 ops/sec ±3.82% (85 runs sampled)
this curry piecemeal application with 9 arguments x 45,527 ops/sec ±4.91% (80 runs sampled)
lodash piecemeal application with 10 arguments x 30,946 ops/sec ±1.21% (85 runs sampled)
this curry piecemeal application with 10 arguments x 40,001 ops/sec ±4.57% (79 runs sampled)

To run the benchmarks locally execute in the project repository:

npm install
npm run benchmark

License

GPL 3.0 licensed