🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

fn-proxy

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fn-proxy

Simple function proxying.

0.0.0
latest
Source
npm
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

proxy

FAQs

Package last updated on 10 Mar 2015

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