You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

functional.js

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

functional.js - npm Package Compare versions

Comparing version

to
0.1.14

47

functional.js
var λ = (function () {
var λ = {};
var λ = {}, hardReturn = "hardReturn;";

@@ -33,7 +33,7 @@ var sliceArgs = function (args) {

λ.each = λ.curry(function (iterator, items) {
if (!items || typeof (iterator) !== "function") {
return;
}
checkFunction(iterator);
for (var i = 0; i < items.length; i++) {
iterator(items[i]);
if (iterator.call(null, items[i], i) === hardReturn) {
return;
}
}

@@ -43,7 +43,5 @@ });

λ.map = λ.curry(function (iterator, items) {
checkFunction(iterator);
var mapped = [],
mapEach;
if (!items || typeof (iterator) !== "function") {
return;
}
mapEach = λ.each(function () {

@@ -57,7 +55,5 @@ mapped.push(iterator.apply(null, arguments));

λ.reduce = λ.reducel = λ.curry(function (iterator, initial, items) {
checkFunction(iterator);
var cumulate = initial,
reduceEach;
if (!items || typeof (iterator) !== "function") {
return;
}
reduceEach = λ.each(function (item) {

@@ -70,10 +66,17 @@ cumulate = iterator.call(null, cumulate, item);

λ.clone = function (items) {
var clone = [];
λ.each(function (item) {
clone.push(item);
}, items);
return clone;
};
λ.first = λ.curry(function (iterator, items) {
checkFunction(iterator);
var first;
if (typeof (iterator) !== "function") {
throw "λ Error: Invalid function";
}
λ.each(function (item) {
if (!first && iterator.call(null, item)) {
if (iterator.call(null, item)) {
first = item;
return hardReturn;
}

@@ -85,12 +88,4 @@ }, items);

λ.last = λ.curry(function (iterator, items) {
var last;
if (typeof (iterator) !== "function") {
throw "λ Error: Invalid function";
}
λ.each(function (item) {
if (iterator.call(null, item)) {
last = item;
}
}, items);
return last;
var itemsClone = λ.clone(items);
return λ.first(iterator, itemsClone.reverse());
});

@@ -115,3 +110,3 @@

isAny = true;
return;
return hardReturn;
}

@@ -118,0 +113,0 @@ }, items);

/*!
functional.js (v0.1.12) 02-09-2013
functional.js (v0.1.14) 03-09-2013
(c) Lee Crossley <leee@hotmail.co.uk> (http://ilee.co.uk/)
*/
var λ=function(){var a={},b=function(a){return a.length>0?[].slice.call(a,0):[]},c=function(a){if(!a||"function"!=typeof a)throw"λ Error: Invalid function"};return a.curry=function(d){return c(d),function e(){var c=b(arguments);if(c.length===d.length)return d.apply(null,c);if(c.length>d.length){var f=d.apply(null,c);return a.reduce(d,f,c.slice(d.length))}return function(){var a=b(arguments);return e.apply(null,c.concat(a))}}},a.each=a.curry(function(a,b){if(b&&"function"==typeof a)for(var c=0;c<b.length;c++)a(b[c])}),a.map=a.curry(function(b,c){var d,e=[];if(c&&"function"==typeof b)return d=a.each(function(){e.push(b.apply(null,arguments))}),d(c),e}),a.reduce=a.reducel=a.curry(function(b,c,d){var e,f=c;if(d&&"function"==typeof b)return e=a.each(function(a){f=b.call(null,f,a)}),e(d),f}),a.first=a.curry(function(b,c){var d;if("function"!=typeof b)throw"λ Error: Invalid function";return a.each(function(a){!d&&b.call(null,a)&&(d=a)},c),d}),a.last=a.curry(function(b,c){var d;if("function"!=typeof b)throw"λ Error: Invalid function";return a.each(function(a){b.call(null,a)&&(d=a)},c),d}),a.every=a.all=a.curry(function(b,d){c(b);var e=!0;return a.each(function(a){b.call(null,a)||(e=!1)},d),e}),a.any=a.curry(function(b,d){c(b);var e=!1;return a.each(function(a){return b.call(null,a)?(e=!0,void 0):void 0},d),e}),a.select=a.curry(function(b,d){c(b);var e,f=[];return e=a.each(function(a){b.call(null,a)&&f.push(a)}),e(d),f}),a.compose=function(c){var d=a.any(function(a){return"function"!=typeof a});if(c=b(arguments),d(c))throw"λ Error: Invalid function to compose";return function(){var b=arguments,d=a.each(function(a){b=[a.apply(null,b)]});return d(c.reverse()),b[0]}},a.partition=a.curry(function(b,d){c(b);var e,f=[],g=[];return e=a.each(function(a){(b.call(null,a)?f:g).push(a)}),e(d),[f,g]}),a}();"undefined"!=typeof exports&&("undefined"!=typeof module&&module.exports&&(exports=module.exports=λ),exports.λ=λ);
var λ=function(){var a={},b="hardReturn;",c=function(a){return a.length>0?[].slice.call(a,0):[]},d=function(a){if(!a||"function"!=typeof a)throw"λ Error: Invalid function"};return a.curry=function(b){return d(b),function e(){var d=c(arguments);if(d.length===b.length)return b.apply(null,d);if(d.length>b.length){var f=b.apply(null,d);return a.reduce(b,f,d.slice(b.length))}return function(){var a=c(arguments);return e.apply(null,d.concat(a))}}},a.each=a.curry(function(a,c){d(a);for(var e=0;e<c.length;e++)if(a.call(null,c[e],e)===b)return}),a.map=a.curry(function(b,c){d(b);var e,f=[];return e=a.each(function(){f.push(b.apply(null,arguments))}),e(c),f}),a.reduce=a.reducel=a.curry(function(b,c,e){d(b);var f,g=c;return f=a.each(function(a){g=b.call(null,g,a)}),f(e),g}),a.clone=function(b){var c=[];return a.each(function(a){c.push(a)},b),c},a.first=a.curry(function(c,e){d(c);var f;return a.each(function(a){return c.call(null,a)?(f=a,b):void 0},e),f}),a.last=a.curry(function(b,c){var d=a.clone(c);return a.first(b,d.reverse())}),a.every=a.all=a.curry(function(b,c){d(b);var e=!0;return a.each(function(a){b.call(null,a)||(e=!1)},c),e}),a.any=a.curry(function(c,e){d(c);var f=!1;return a.each(function(a){return c.call(null,a)?(f=!0,b):void 0},e),f}),a.select=a.curry(function(b,c){d(b);var e,f=[];return e=a.each(function(a){b.call(null,a)&&f.push(a)}),e(c),f}),a.compose=function(b){var d=a.any(function(a){return"function"!=typeof a});if(b=c(arguments),d(b))throw"λ Error: Invalid function to compose";return function(){var c=arguments,d=a.each(function(a){c=[a.apply(null,c)]});return d(b.reverse()),c[0]}},a.partition=a.curry(function(b,c){d(b);var e,f=[],g=[];return e=a.each(function(a){(b.call(null,a)?f:g).push(a)}),e(c),[f,g]}),a}();"undefined"!=typeof exports&&("undefined"!=typeof module&&module.exports&&(exports=module.exports=λ),exports.λ=λ);

@@ -6,3 +6,3 @@ {

"homepage": "http://ilee.co.uk",
"version": "0.1.12",
"version": "0.1.14",
"main": "functional.min.js",

@@ -9,0 +9,0 @@ "keywords": [

@@ -179,3 +179,13 @@ describe("functional", function() {

});
it("should be able to λ.clone an array and keep independence", function() {
var items = [5, 4, 3, 2, 1];
var clonedItems = λ.clone(items);
expect(clonedItems).toEqual(items);
items = [];
expect(clonedItems).not.toEqual(items);
});
it("should be able to λ.curry λ.first", function() {

@@ -182,0 +192,0 @@ var items = [5, 4, 3, 2, 1];