Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fluture-js/callgebra
The little algebra of callbacks
https://github.com/fluture-js/callgebra
algebraic-data-types callbacks functional-programming
Last synced: 2 days ago
JSON representation
The little algebra of callbacks
- Host: GitHub
- URL: https://github.com/fluture-js/callgebra
- Owner: fluture-js
- License: mit
- Created: 2018-12-28T15:25:30.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-04-06T13:20:43.000Z (over 3 years ago)
- Last Synced: 2024-09-15T00:11:06.340Z (2 months ago)
- Topics: algebraic-data-types, callbacks, functional-programming
- Language: JavaScript
- Size: 54.7 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# 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][1].## Usage
### Node
```console
$ 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.```js
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:
- [Skypack](https://cdn.skypack.dev/[email protected])
- [JSPM](https://jspm.dev/[email protected])
- [jsDelivr](https://cdn.jsdelivr.net/npm/[email protected]/+esm)### Old Browsers and Code Pens
There's a [UMD][] file included in the NPM package, also available via
jsDelivr: https://cdn.jsdelivr.net/npm/[email protected]/dist/umd.jsThis file adds `flutureProject` to the global scope, or use CommonJS/AMD
when available.```js
const {of, callback} = require ('callgebra');
callback (console.log) (of (42));
```## API
```hs
type Callback a b = (b -> a) -> a
```#### `of :: a -> Callback b a`
Creates a callback for a given return value.
#### `chain :: (a -> Callback c b) -> Callback c a -> Callback c b`
Sequence two callback-accepting functions.
#### `map :: (a -> b) -> Callback c a -> Callback c b`
Modify the return value of a callback.
#### `ap :: Callback c (a -> b) -> Callback c a -> Callback c b`
Apply the function returned by one callback to the value returned by
another.#### `callback :: (a -> b) -> Callback b a -> b`
Given a function and a Callback, runs the Callback using the function.
[1]: https://medium.com/@avaq/composable-callbacks-81c84f0324
[esm]: https://github.com/standard-things/esm
[UMD]: https://github.com/umdjs/umd