Skip to content

A tiny Javascript library to help with promises in functional composition

Notifications You must be signed in to change notification settings

mmcglone/comp-promise

Repository files navigation

comp-promise

Build Status Coverage Status npm version

A tiny Javascript library to help with promises in functional composition

Example Usage

const compose = require('lodash/fp/compose');
const { then } = require('comp-promise');

const fetchUser = id => {
  if (id === 123) {
    return Promise.resolve({
      id: 123,
      firstName: 'John',
	  lastName: 'Smith'
    });
  }
  return Promise.reject(new Error('No such user'));
};

const fullName = user => `${user.firstName} ${user.lastName}`;

const main = compose(
  then(fullName),
  fetchUser
);

main(123); // Returns a promise that resolves to 'John Smith'
main(456); // Returns a promise that rejects with a 'No such user' Error

About

A tiny Javascript library to help with promises in functional composition

Resources

Stars

Watchers

Forks

Packages

No packages published