New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

fish-operator

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fish-operator

Kleisli composition in JS

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

fish

The (>=>) and (<=<) operators in JavaScript. Kinda.

Install

npm install fish-operator

Usage

The first parameter of these functions is the string or Symbol key of the bind method for the objects returned by the functions to compose. A bind method will have the signature bind :: (A -> m<B>) -> m<B> for a given m<A>. For Promises, this will be the then method so you will pass in 'then' as the first parameter. The following examples show this idea using Promise-returning functions:

const { compose, pipe } = require('fish-operator');

const f = x => Promise.resolve(x + 1);
const g = x => Promise.resolve(x * 2);

const h = compose('then')(f, g);
await h(10);
// <- 21

const j = pipe('then')(f, g);
await h(10);
// <- 22

In the real world, you would probably use these functions like this:

const { pipe } = require('fish-operator');
const pipeP = pipe('then');
const prop = key => obj => obj[key];

// Fictitious Promise-returning API functions...
const getUserById = _id => Promise.resolve({ _id, name: 'Susan', jobId: 2 });
const getJobById = _id => Promise.resolve({ _id, name: 'Rattlesnake Groomer' });

const getJobByUserId = pipeP(getUserById, prop('jobId'), getJobById, prop('name'));
await getJobByUserId(10);
// <- 'Rattlesnake Groomer'

Each function accepts any number of functions that return either a value or an object with a method that matches the bindKey parameter given.

License

WTFPL

Keywords

composition

FAQs

Package last updated on 05 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts