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

ducklings

v0.5.0

Published

Combinators!

Downloads

5

Readme

ducklings

Combinators!

Usage

Install:

npm i ducklings

Use:

import { I, K, R, /* ... */ } from 'ducklings'

API

Here are the provided combinators:

export const E = {}

export const I = a => a
export const K = a => () => a
export const G = ps => a => ps.reduce((o, p) => o == undefined ? undefined : o[p] , a)
export const D = a => b => b == undefined ? a : b
export const T = a => f => f(a)
export const V = a => b => f => f(a)(b)

const N = F => f => g => g === E ? a => f(a) : N(F)(F(f)(g))
const TN = F => a => f => g => g === E ? f(a) : TN(F)(a)(F(f)(g))

export const B = f => g => a => f(g(a))
export const C = N(B)

export const P = f => g => a => g(f(a))
export const Q = N(P)
export const R = TN(P)

What?

Okay, here are the provided combinators with some explanations and examples of how you would use them:

Identity (I)

You need a function that just passes a value through. Use I.

Constant (K)

You have a value, but you need to pass a function. Use K(value).

Get (G)

You want to safely get a deep property from an object.

// This will return `undefined` without blowing up if the object is `null` or `undefined`,
// or if any property along the path does not exist.
G(['deeply', 'nested', 'path'])(object)

Default (D)

You want a default value to use in case a function returns null or undefined.

D("default")(null) // returns "default"
D("default")("value") // returns "value"

Thrush (T)

You want to pass a value to a function, but you want the value to be on the left side instead of on the right side.

Vireo (V)

You want to "hold on" to parameters to a function.

Composition (B)

You want to create a function out of two other functions, passing the result of one to the next, from right to left.

const fn = B(fn1)(fn2)
// fn = value => fn1( fn2(value) )

Composition (C)

You want to create a function out of any number of other functions, passing the result of one to the next, from right to left. Pass E (extract) at the end to indicate the end of the pipeline.

const fn = C(fn1)(fn2)(fn3)(fn4)(E)
// fn = value => fn1( fn2( fn3( fn4(value) ) ) )

Composition (D)

You want to pass a value through any number of other functions, passing the result of one to the next, from right to left. Pass E (extract) at the end to indicate the end of the pipeline.

const result = D(value)(fn1)(fn2)(fn3)(fn4)(E)
// result = fn1( fn2( fn3( fn4(value) ) ) )

Pipeline (P)

You want to create a function out of two other functions, passing the result of one to the next, from left to right.

const fn = P(fn1)(fn2)
// fn = value => fn2( fn1(value) )

Pipeline (Q)

You want to create a function out of any number of other functions, passing the result of one to the next, from left to right. Pass E (extract) at the end to indicate the end of the pipeline.

const fn = Q(fn1)(fn2)(fn3)(fn4)(E)
// fn = value => fn4( fn3( fn2( fn1(value) ) ) )

Pipeline (R)

You want to pass a value through any number of other functions, passing the result of one to the next, from left to right. Pass E (extract) at the end to indicate the end of the pipeline.

const result = R(value)(fn1)(fn2)(fn3)(fn4)(E)
// result = fn4( fn3( fn2( fn1(value) ) ) )

Further Reading and Watching