/callgebra

The little algebra of callbacks

Primary LanguageJavaScriptMIT LicenseMIT

Callgebra

The little algebra of callbacks.

Introduction

This package exports functions for composing callbacks. You can read about the idea in my Medium post about composable callbacks.

Usage

Node

$ npm install --save callgebra

On Node 12 and up, this module can be loaded directly with import or require. On Node versions below 12, require or the esm-loader can be used.

import {of, callback} from 'callgebra';
callback (console.log) (of (42));

Deno and Modern Browsers

You can load the EcmaScript module from various content delivery networks:

Old Browsers and Code Pens

There's a UMD file included in the NPM package, also available via jsDelivr: https://cdn.jsdelivr.net/npm/callgebra@2.1.0/dist/umd.js

This file adds flutureProject to the global scope, or use CommonJS/AMD when available.

const {of, callback} = require ('callgebra');
callback (console.log) (of (42));

API

type Callback a b = (b -> a) -> a

Creates a callback for a given return value.

Sequence two callback-accepting functions.

Modify the return value of a callback.

Apply the function returned by one callback to the value returned by another.

Given a function and a Callback, runs the Callback using the function.