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

infinite-application

v0.4.0

Published

A wrapper to provide an endless interface for partial application.

Downloads

9

Readme

infiniteApplication

Build Status

Overview

infiniteApplication is a wrapper that provides infinite partial application of a function using variable arity, or a single config object.

Installation

npm i infinite-application

Usage

Importing/Requiring

ES6

import infiniteApplication from 'infinite-application';

NodeJS/CommonJS

const infiniteApplication = require('infinite-application');

The infiniteApplication Wrapper

infiniteApplication(fn, [useConfigForArgs], [...initialArgs])

Returns an infiniteApplication wrapped function (see below).

  • fn: function -- The function you wish to use with endless partial application.
  • useConfigForArgs (optional): boolean -- A flag indicating whether the passed fn is called with multiple separate arguments, or with a single configuration object argument. Defaults to false.
  • ...initialArgs (optional): Any initial arguments you would like to pass for partial application against the passed fn.

The Wrapped Function

The wrapper returned from infiniteApplication provides an interface for arbitrary, unlimited partial application of arguments against the passed fn value. The form of the wrapper depends on the useConfigForArgs value that was passed to infiniteApplication.

Separate Arguments Form

Returned when useConfigForArgs is false or omitted from the call to infiniteApplication

individualArgWrappedFn([...args])

Returns itself, so chaining is possible.

  • ...args: Any non-zero number of arguments to be partially applied to the function passed as fn to infiniteApplication.

If no argument is passed, the original function passed as fn will be executed with whatever arguments have been passed thus far.

For example, consider the following function:

function speak(fname, lname, line) {
    return `${fname}${lname ? ` ${lname}` : ''}: "${line}"`;
}

This function takes its arguments separately, so we can omit the useConfigForArgs flag and just pass it into infiniteApplication to get the single arg wrapped version:

const wrappedSpeak = infiniteApplication(speak);

You now have the ability to call this partially, with any number of non-zero args. Once you are ready to actually invoke the function with the passed args, simply call the wrapper without any arguments.

Consider the examples below:

const wrappedSpeak = infiniteApplication(speak);
wrappedSpeak('Peter');
wrappedSpeak('Venkman');
wrappedSpeak('What do you see?');
wrappedSpeak(); // returns "Peter Venkman: "What do you see?""
const wrappedSpeak = infiniteApplication(speak);
wrappedSpeak('Ray', 'Stantz');
wrappedSpeak('This place is great!');
wrappedSpeak(); //returns "Ray Stanz: "This place is great!""
const wrappedSpeak = infiniteApplication(speak);
wrappedSpeak('Egon')('Spengler')('I\'d like to take a few samples.')(); // returns "Egon Spengler: "I'd like to take a few samples.""
const wrappedSpeak = infiniteApplication(speak, false, 'Winston', 'Zeddemore');
wrappedSpeak('Ray, when someone asks you if you\'re a god, you say "YES"!');
wrappedSpeak(); // returns "Winston Zeddemore: "Ray, when someone asks you if you're a god, you say "YES"!"""
const wrappedSpeak = infiniteApplication(speak);
wrappedSpeak('Slimer');
wrappedSpeak(undefined);
wrappedSpeak('Blaaaaaarghargharghhh!!!!!');
wrappedSpeak(); // return "Slimer: "Blaaaaaarghargharghhh!!!!!""

Config Argument Form

Returned when useConfigForArgs is true in the call to infiniteApplication

configArgWrappedFn(argConfigObj)

Returns itself, so chaining is possible.

  • argConfigObj: An object that will be extended into the previously held object in the closure.

If no argument is passed, the original function passed as fn will be executed with whatever the current state of the cached config object is.

For example, consider the following function:

function speak({fname, lname, line}) {
    return `${fname}${lname ? ` ${lname}` : ''}: "${line}"`;
}

Note that the args are destructured in a single config object.

When we pass this version of speak to infiniteApplication, we need to pass true as the the second useConfigForArgs arg:

const wrappedSpeak = infiniteApplication(speak, true);

You now have a wrapped function that can be called wit a config object containing any subset of the possible keys therein. If a duplicate key is passed, the latest value overrides the last one.

Just as with the separate args form, to invoke the function with the passed args, simply call the wrapper without any arguments.

Consider the examples below:

const wrappedSpeak = infiniteApplication(speak, true);
wrappedSpeak({fname: "Louis", lname: "Tully"});
wrappedSpeak({line: "I am The Keymaster!"});
wrappedSpeak(); // returns "Louis Tully: "I am The Keymaster!""
const wrappedSpeak = infiniteApplication(speak, true, {fname: 'Dana', lname: 'Barrett'});
wrappedSpeak({fname: 'The GateKeeper'});
wrappedSpeak({lname: undefined});
wrappedSpeak('I am The GateKeeper!');
wrappedSpeak(); // returns "The GateKeeper: "I am The Gatekeeper!""
const choose = infiniteApplication(speak, true, {fname: 'Gozer'}, {line: 'CHOOSE!!!'})(); // assigns choose as "Gozer: "CHOOSE!!!""