0.5.1 • Published 5 years ago

partial-application-tree v0.5.1

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

partial-application-tree

This module is designed to simplify making your library's codebase functional via partial application.

By using partial applicatio on your functions you are able to keep them pure when they would have otherwise been impure.

const doAjaxRequest = (url) => {
  // some ajax
};

const myFunc = (doAjaxRequest) => {
  return doAjaxRequest('url').then((response) => {
    return 'something';
  });
};

As you can see in this code example myFunc is a pure function (when given a pure function). This allows it to be easily tested if you pass in a pure stub.

Usage

// Codebase
export const leaf = () => 'leaf';

export const node = (leaf) => leaf();

// Your wiring up code (usually in index.js or module.js)
import pat from 'partial-application-tree';
import { leaf, node } from './code';

const tree = [
  ['node', ['leaf']]
];

const codebase = pat(tree, {
  leaf,
  node,
});

There is added support for nested nodes. The paths are automatically resolved.

const tree = [
  ['nested.node', ['deep.leaf']]
];
0.5.1

5 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago