Socket
Socket
Sign inDemoInstall

ap

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1 to 0.1.0

2

examples/z.js

@@ -1,2 +0,2 @@

var ap = require('ap');
var ap = require('../');
var z = ap([3], function (x, y) {

@@ -3,0 +3,0 @@ return this.z * (x * 2 + y);

@@ -1,16 +0,17 @@

var exports = module.exports = function (args, fn) {
exports = module.exports = ap;
function ap (args, fn) {
return function () {
return fn.apply(this, args.concat.apply(args, arguments));
};
};
}
exports.ap = exports;
exports.pa = function (args, fn) {
exports.pa = pa;
function pa (args, fn) {
return function () {
return fn.apply(this, [].slice.call(arguments).concat(args));
};
};
}
exports.apa = function (left, right, fn) {
exports.apa = apa;
function apa (left, right, fn) {
return function () {

@@ -21,7 +22,23 @@ return fn.apply(this,

};
};
}
exports.curry = function (fn) {
exports.partial = partial;
function partial (fn) {
var args = [].slice.call(arguments, 1);
return exports.ap(args, fn);
};
return ap(args, fn);
}
exports.partialRight = partialRight;
function partialRight (fn) {
var args = [].slice.call(arguments, 1);
return pa(args, fn);
}
exports.curry = curry;
function curry (fn) {
return partial(partial, fn);
}
exports.curryRight = function curryRight (fn) {
return partial(partialRight, fn);
}
{
"name" : "ap",
"version" : "0.0.1",
"version" : "0.1.0",
"description" : "Currying in javascript. Like .bind() without also setting `this`.",

@@ -22,3 +22,3 @@ "main" : "./index.js",

"devDependencies" : {
"expresso" : ">=0.6.0"
"tap" : "0.2.5"
},

@@ -31,3 +31,3 @@ "author" : {

"scripts" : {
"test" : "expresso"
"test" : "tap ./test"
},

@@ -34,0 +34,0 @@ "license" : "MIT/X11",

@@ -1,40 +0,137 @@

var assert = require('assert');
var ap = require('ap');
var test = require("tap").test;
exports.ap = function () {
assert.eql(
ap([3], function (x, y) { return x * 2 + y })(4),
3 * 2 + 4
);
assert.eql(
ap([3,4], function (x, y, z, w) { return x * 2 + (y + z) * w })(5,6),
3 * 2 + (4 + 5) * 6
);
assert.eql(
ap([3], function (x, y) {
return this.z * (x * 2 + y)
}).call({ z : 10 }, 4),
10 * (3 * 2 + 4)
);
var ap = require('../');
var pa = ap.pa;
var apa = ap.apa;
var partial = ap.partial;
var partialRight = ap.partialRight;
var curry = ap.curry;
var curryRight = ap.curryRight;
function one(x, y) {
return x * 2 + y
}
function two(x, y, z, w) {
return x * 2 + (y + z) * w
}
function three(x, y) {
return this.z * (x * 2 + y)
}
var z = {
z: 10
};
exports.pa = function () {
assert.eql(
ap.pa([3], function (x, y) { return x * 2 + y })(4),
4 * 2 + 3
);
assert.eql(
ap.pa([3,4], function (x, y, z, w) { return x * 2 + (y + z) * w })(5,6),
5 * 2 + (6 + 3) * 4
);
assert.eql(
ap.pa([3], function (x, y) {
return this.z * (x * 2 + y)
}).call({ z : 10 }, 4),
10 * (4 * 2 + 3)
);
};
test("ap function", function (t) {
var apOne = ap([3], one);
t.equal(apOne(4),
3 * 2 + 4);
var apTwo = ap([3,4], two);
t.equal(apTwo(5, 6),
3 * 2 + (4 + 5) * 6);
var apThree = ap([3], three);
t.equal(apThree.call(z, 4),
10 * (3 * 2 + 4));
t.end();
});
test("pa function", function (t) {
var paOne = pa([3], one);
t.equal(paOne(4),
4 * 2 + 3);
var paTwo = pa([3,4], two);
t.equal(paTwo(5, 6),
5 * 2 + (6 + 3) * 4);
var paThree = pa([3], three);
t.equal(paThree.call(z, 4),
10 * (4 * 2 + 3));
t.end();
});
test("apa function", function (t) {
var apaOne = apa([3], [4], one);
t.equal(apaOne(),
3 * 2 + 4);
var apaTwo = apa([3], [4], two);
t.equal(apaTwo(5, 6),
3 * 2 + (5 + 6) * 4);
var apaThree = apa([3], [4], three);
t.equal(apaThree.call(z),
10 * (3 * 2 + 4));
t.end();
});
test("partial function", function (t) {
var apOne = partial(one, 3);
t.equal(apOne(4),
3 * 2 + 4);
var apTwo = partial(two, 3, 4);
t.equal(apTwo(5, 6),
3 * 2 + (4 + 5) * 6);
var apThree = partial(three, 3);
t.equal(apThree.call(z, 4),
10 * (3 * 2 + 4));
t.end();
});
test("partialRight function", function (t) {
var paOne = partialRight(one, 3);
t.equal(paOne(4),
4 * 2 + 3);
var paTwo = partialRight(two, 3, 4);
t.equal(paTwo(5, 6),
5 * 2 + (6 + 3) * 4);
var paThree = partialRight(three, 3);
t.equal(paThree.call(z, 4),
10 * (4 * 2 + 3));
t.end();
});
test("curry function", function (t) {
var apOne = curry(one)(3);
t.equal(apOne(4),
3 * 2 + 4, "curry one");
var apTwo = curry(two)(3, 4);
t.equal(apTwo(5, 6),
3 * 2 + (4 + 5) * 6, "curry two");
var apThree = curry(three)(3);
t.equal(apThree.call(z, 4),
10 * (3 * 2 + 4), "curry three");
t.end();
});
test("curryRight function", function (t) {
var paOne = curryRight(one)(3);
t.equal(paOne(4),
4 * 2 + 3);
var paTwo = curryRight(two)(3, 4);
t.equal(paTwo(5, 6),
5 * 2 + (6 + 3) * 4);
var paThree = curryRight(three)(3);
t.equal(paThree.call(z, 4),
10 * (4 * 2 + 3));
t.end();
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc