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

copb

v1.0.1

Published

A functional composition framework built for TypesScript that provides type safety without the need for the usual countless overloads, thanks to some functional type trickery.

Downloads

3

Readme

copb Version Build Status

A functional composition helper for TypesScript that provides type safety without the need for the usual countless overloads, thanks to some functional type trickery.

This module contains just 4 curried functions: c, o, p, b.

npm install

copb is available on npm as well as https://deno.land/x/copb.

npm install --save copb

The functions

b

b is a simple curried binary composition function, which the other functions use under the hood.

import { b } from "https://deno.land/x/copb/mod.ts";

const f = (x: number) => x / 4;
const g = (x: number) => x - 5;

// h = f ∘ g
const h = b(f)(g);

console.log(h(13)); // -> 2

c

c for callable is used to build compositional stacks generated by o and p. Once built, the resultant composed function can be applied in the normal way. See usage in the sections below.

o

o (named after the mathematical composition symbol) is for more complex compositions, with the ability to compose any number of uniary functions together.

import { b } from "https://deno.land/x/copb/mod.ts";

const f = (x: string) => "number " + x;
const g = (x: number) => String(x);
const h = (x: number) => x / 3;
const l = (x: number) => x - 6;

// m = f ∘ g ∘ h ∘ l
const m = c(o(f)(g)(h)(l));

console.log(m(15)); // -> "number 3"

p

p for pipeline is used to pipe the results of functions to each other. It is identical to o except it is read from left to right.

import { b } from "https://deno.land/x/copb/mod.ts";

const f = (x: string) => "number " + x;
const g = (x: number) => String(x);
const h = (x: number) => x / 3;
const l = (x: number) => x - 6;

// m = f ∘ g ∘ h ∘ l
const m = c(p(l)(h)(g)(f));

console.log(m(15)); // -> "number 3"

Usage notes

Applying a layer of abstraction, you can think of the o and p functions as having nodes within the compositional stack. Each of these nodes is denoted in a seperate set of brackets.

c(o(node1)(node2)(node3));

When necessary, type annotations can be placed between nodes. For o, each annotation somewhat counterintuitively represents the input type of the following node, and the second annotation of the first node represents the final result.

const m = c(o<string, string>(f)<number>(g)<number>(h)<number>(l));

For p, each annotation represents the output type of the following node, and the second annotation of the first node represents the final input.

const m = c(p<number, number>(l)<number>(h)<string>(g)<string>(f));

API

Generated API documentation, with pseudohaskell illustrations of type signatures, is available here.

Comments

Intellisense

Your IDE will probably show a disgusting, monstrosity of a type signature. That's because this project uses recursive types in order to provide robust type safety. Type checking is still completely functional.