Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

fn-proxy

0.0.0 • Public • Published

fn-proxy

Simple function proxying. Allows for point-free recursion in JavaScrpipt, and simulation of lazy function evaluation.

Install

$ npm install fn-proxy

Run the specs (make sure jasmine-node is installed)

$ npm test

Usage

Require the module

var proxy = require('fn-proxy');
Examples

All examples show a point free recursive strategy for finding the length of a list. This would normally not be possible with regular JavaScript. Also note: examples use point-free style functions, something like ramda or lodash would provide.

  • Explicit proxy - save proxy after declaration
var length = ifElse(isEmpty, always(0), compose(inc, proxy('length'), tail));
 
proxy('length', length);
 
length([]) // => 0
length([1, 2, 3, 4]) // => 4
  • Short-hand proxy chaining
var length = ifElse(
  isEmpty, always(0), compose(inc, proxy('length'), tail)
).proxy('length');
 
length([]) // => 0
length([1, 2, 3, 4]) // => 4
  • Wrap declaration with proxy
var length = proxy('length', ifElse(
  isEmpty, always(0), compose(inc, proxy('length'), tail)
));
 
length([]) // => 0
length([1, 2, 3, 4]) // => 4
  • Invoke the proxy directly
proxy('length', ifElse(isEmpty, always(0), compose(inc, proxy('length'), tail)));
 
proxy('length')([]) // => 0
proxy('length')([1, 2, 3, 4]) // => 4

install

npm i fn-proxy

Downloadsweekly downloads

0

version

0.0.0

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability