functional.js
Advanced tools
Comparing version
@@ -7,3 +7,3 @@ { | ||
"homepage": "http://functionaljs.com", | ||
"version": "0.4.2", | ||
"version": "0.4.5", | ||
"keywords": [ | ||
@@ -10,0 +10,0 @@ "functional", |
@@ -117,16 +117,15 @@ var λ = (function () { | ||
checkFunction(iterator); | ||
var filtered = [], | ||
filterEach; | ||
filterEach = λ.each(function (item) { | ||
var filtered = []; | ||
λ.each(function (item) { | ||
if (iterator.call(null, item)) { | ||
filtered.push(item); | ||
} | ||
}); | ||
filterEach(items); | ||
}, items); | ||
return filtered; | ||
}); | ||
λ.best = λ.curry(function (func, items) { | ||
λ.best = λ.curry(function (iterator, items) { | ||
checkFunction(iterator); | ||
var compare = function (arg1, arg2) { | ||
return func.call(this, arg1, arg2) ? | ||
return iterator.call(this, arg1, arg2) ? | ||
arg1 : arg2; | ||
@@ -137,2 +136,15 @@ }; | ||
λ.while = λ.curry(function (iterator, items) { | ||
checkFunction(iterator); | ||
var result = []; | ||
λ.each(function (item) { | ||
if (iterator.call(null, item)) { | ||
result.push(item); | ||
} else { | ||
return hardReturn; | ||
} | ||
}, items); | ||
return result; | ||
}); | ||
λ.compose = function (funcs) { | ||
@@ -139,0 +151,0 @@ var hasInvalid = λ.any(function (func) { |
/*! | ||
functional.js (v0.4.4) 01-07-2014 | ||
functional.js (v0.4.4) 23-07-2014 | ||
(c) Lee Crossley <leee@hotmail.co.uk> (http://ilee.co.uk/) | ||
*/ | ||
var lambda=function(){"use strict";var a={},b="hardReturn;",c=function(a){return a.length>0?[].slice.call(a,0):[]},d=function(a){if(!a||"function"!=typeof a)throw"lambda 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.fold(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=[];return a.each(function(){e.push(b.apply(null,arguments))},c),e}),a.fold=a.foldl=a.curry(function(b,c,e){return d(b),a.each(function(a){c=b.call(null,c,a)},e),c}),a.reduce=a.reducel=a.foldll=a.curry(function(b,c){d(b);var e=c[0];return c.shift(),a.fold(b,e,c)}),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(c,e){d(c);var f=!0;return a.each(function(a){return c.call(null,a)?void 0:(f=!1,b)},e),f}),a.any=a.contains=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.filter=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.best=a.curry(function(b,c){var d=function(a,c){return b.call(this,a,c)?a:c};return a.reduce(d,c)}),a.compose=function(b){var d=a.any(function(a){return"function"!=typeof a});if(b=c(arguments),d(b))throw"lambda 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.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)},a.toArray=function(b){return a.map(function(a){return[a,b[a]]},Object.keys(b))},a.apply=a.curry(function(b,c){var d=[];return a.isArray(b)&&(d=[].slice.call(b,1),b=b[0]),a.map(function(a){return a[b].apply(a,d)},c)}),a.assign=a.extend=a.curry(function(b,c){return a.each(function(a){c[a]=b[a]},Object.keys(b)),c}),a.prop=function(a){return function(b){return b[a]}},a.pluck=a.curry(function(b,c){return a.map(a.prop(b),c)}),a.exists=function(a){return null!=a},a.truthy=function(b){return a.exists(b)&&b!==!1},a.falsy=function(b){return!a.truthy(b)},a}();"undefined"!=typeof exports&&("undefined"!=typeof module&&module.exports&&(exports=module.exports=lambda),exports.lambda=lambda); | ||
var lambda=function(){"use strict";var a={},b="hardReturn;",c=function(a){return a.length>0?[].slice.call(a,0):[]},d=function(a){if(!a||"function"!=typeof a)throw"lambda 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.fold(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=[];return a.each(function(){e.push(b.apply(null,arguments))},c),e}),a.fold=a.foldl=a.curry(function(b,c,e){return d(b),a.each(function(a){c=b.call(null,c,a)},e),c}),a.reduce=a.reducel=a.foldll=a.curry(function(b,c){d(b);var e=c[0];return c.shift(),a.fold(b,e,c)}),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(c,e){d(c);var f=!0;return a.each(function(a){return c.call(null,a)?void 0:(f=!1,b)},e),f}),a.any=a.contains=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.filter=a.curry(function(b,c){d(b);var e=[];return a.each(function(a){b.call(null,a)&&e.push(a)},c),e}),a.best=a.curry(function(b,c){d(b);var e=function(a,c){return b.call(this,a,c)?a:c};return a.reduce(e,c)}),a.while=a.curry(function(c,e){d(c);var f=[];return a.each(function(a){return c.call(null,a)?void f.push(a):b},e),f}),a.compose=function(b){var d=a.any(function(a){return"function"!=typeof a});if(b=c(arguments),d(b))throw"lambda 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.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)},a.toArray=function(b){return a.map(function(a){return[a,b[a]]},Object.keys(b))},a.apply=a.curry(function(b,c){var d=[];return a.isArray(b)&&(d=[].slice.call(b,1),b=b[0]),a.map(function(a){return a[b].apply(a,d)},c)}),a.assign=a.extend=a.curry(function(b,c){return a.each(function(a){c[a]=b[a]},Object.keys(b)),c}),a.prop=function(a){return function(b){return b[a]}},a.pluck=a.curry(function(b,c){return a.map(a.prop(b),c)}),a.exists=function(a){return null!=a},a.truthy=function(b){return a.exists(b)&&b!==!1},a.falsy=function(b){return!a.truthy(b)},a}();"undefined"!=typeof exports&&("undefined"!=typeof module&&module.exports&&(exports=module.exports=lambda),exports.lambda=lambda); |
/*! | ||
functional.js (v0.4.4) 01-07-2014 | ||
functional.js (v0.4.4) 23-07-2014 | ||
(c) Lee Crossley <leee@hotmail.co.uk> (http://ilee.co.uk/) | ||
*/ | ||
var λ=function(){"use strict";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.fold(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=[];return a.each(function(){e.push(b.apply(null,arguments))},c),e}),a.fold=a.foldl=a.curry(function(b,c,e){return d(b),a.each(function(a){c=b.call(null,c,a)},e),c}),a.reduce=a.reducel=a.foldll=a.curry(function(b,c){d(b);var e=c[0];return c.shift(),a.fold(b,e,c)}),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(c,e){d(c);var f=!0;return a.each(function(a){return c.call(null,a)?void 0:(f=!1,b)},e),f}),a.any=a.contains=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.filter=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.best=a.curry(function(b,c){var d=function(a,c){return b.call(this,a,c)?a:c};return a.reduce(d,c)}),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.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)},a.toArray=function(b){return a.map(function(a){return[a,b[a]]},Object.keys(b))},a.apply=a.curry(function(b,c){var d=[];return a.isArray(b)&&(d=[].slice.call(b,1),b=b[0]),a.map(function(a){return a[b].apply(a,d)},c)}),a.assign=a.extend=a.curry(function(b,c){return a.each(function(a){c[a]=b[a]},Object.keys(b)),c}),a.prop=function(a){return function(b){return b[a]}},a.pluck=a.curry(function(b,c){return a.map(a.prop(b),c)}),a.exists=function(a){return null!=a},a.truthy=function(b){return a.exists(b)&&b!==!1},a.falsy=function(b){return!a.truthy(b)},a}();"undefined"!=typeof exports&&("undefined"!=typeof module&&module.exports&&(exports=module.exports=λ),exports.λ=λ); | ||
var λ=function(){"use strict";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.fold(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=[];return a.each(function(){e.push(b.apply(null,arguments))},c),e}),a.fold=a.foldl=a.curry(function(b,c,e){return d(b),a.each(function(a){c=b.call(null,c,a)},e),c}),a.reduce=a.reducel=a.foldll=a.curry(function(b,c){d(b);var e=c[0];return c.shift(),a.fold(b,e,c)}),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(c,e){d(c);var f=!0;return a.each(function(a){return c.call(null,a)?void 0:(f=!1,b)},e),f}),a.any=a.contains=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.filter=a.curry(function(b,c){d(b);var e=[];return a.each(function(a){b.call(null,a)&&e.push(a)},c),e}),a.best=a.curry(function(b,c){d(b);var e=function(a,c){return b.call(this,a,c)?a:c};return a.reduce(e,c)}),a.while=a.curry(function(c,e){d(c);var f=[];return a.each(function(a){return c.call(null,a)?void f.push(a):b},e),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.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)},a.toArray=function(b){return a.map(function(a){return[a,b[a]]},Object.keys(b))},a.apply=a.curry(function(b,c){var d=[];return a.isArray(b)&&(d=[].slice.call(b,1),b=b[0]),a.map(function(a){return a[b].apply(a,d)},c)}),a.assign=a.extend=a.curry(function(b,c){return a.each(function(a){c[a]=b[a]},Object.keys(b)),c}),a.prop=function(a){return function(b){return b[a]}},a.pluck=a.curry(function(b,c){return a.map(a.prop(b),c)}),a.exists=function(a){return null!=a},a.truthy=function(b){return a.exists(b)&&b!==!1},a.falsy=function(b){return!a.truthy(b)},a}();"undefined"!=typeof exports&&("undefined"!=typeof module&&module.exports&&(exports=module.exports=λ),exports.λ=λ); |
@@ -6,3 +6,3 @@ { | ||
"homepage": "http://functionaljs.com", | ||
"version": "0.4.4", | ||
"version": "0.4.5", | ||
"main": "functional.min.js", | ||
@@ -9,0 +9,0 @@ "keywords": [ |
12
spec.js
@@ -201,2 +201,14 @@ describe("functional", function() { | ||
it("should be able to λ.curry λ.while to get even numbers until odd", function() { | ||
var even = function (item) { | ||
return item % 2 === 0; | ||
}; | ||
var whileEven = λ.while(even); | ||
expect(whileEven([2])).toEqual([2]); | ||
expect(whileEven([2, 4, 5, 6])).toEqual([2, 4]); | ||
expect(whileEven([1, 4, 6, 8])).toEqual([]); | ||
}); | ||
it("should be able to use λ.any or λ.contains", function() { | ||
@@ -203,0 +215,0 @@ expect(λ.any).toEqual(λ.contains); |
35704
2.77%765
2.68%