diff --git a/lib/Default.js b/lib/Default.js index e308b19..caa66de 100644 --- a/lib/Default.js +++ b/lib/Default.js @@ -4,6 +4,7 @@ export default (() => { function compose(...funcs) { if (!funcs.length) throw "Must specify functions to compose"; if (funcs.some((x) => !(x instanceof Function))) throw "Functions only allowed"; + return funcs.reduce((composed, toCompose) => ((...args) => toCompose(composed(...args))), funcs.shift()); } @@ -29,6 +30,7 @@ export default (() => { Object.defineProperty(fn, 'arity', { value: (fn.arity || fn.length), writable: true }); Object.defineProperty(curried, 'arity', { value: fn.arity, writable: true }); + return curried; } diff --git a/lib/Identity.js b/lib/Identity.js index 5a30e46..03ac3cd 100644 --- a/lib/Identity.js +++ b/lib/Identity.js @@ -1,5 +1,10 @@ "use strict"; -export default { - Identity(v) { return v; } -}; \ No newline at end of file +export default (() => { + let Identity = (v) => v; + + return { + id: Identity, + Identity + }; +})(); \ No newline at end of file diff --git a/lib/Validator.js b/lib/Validator.js index 42f59cc..f3f0aa1 100644 --- a/lib/Validator.js +++ b/lib/Validator.js @@ -7,13 +7,22 @@ export default (() => { } where(predicate) { - return predicate(this.value) ? Validator.valid(this.value) : Validator.invalid(this.value); + return predicate(this.value) + ? Validator.valid(this.value) + : Validator.invalid(this.value); } - static from(v) { return new Validator(v); } + static from(v) { + return new Validator(v); + } + + static valid(v) { + return new Valid(v); + } - static valid(v) { return new Valid(v); } - static invalid(v) { return new Invalid(v); } + static invalid(v) { + return new Invalid(v); + } } class Valid extends Validator { diff --git a/package.json b/package.json index 2340340..bc1f267 100644 --- a/package.json +++ b/package.json @@ -4,18 +4,17 @@ "description": " Holder of various Functional Programming utilities", "main": "compiled/dist/FunctionalProgrammingUtilities.js", "scripts": { - "test": "mocha --compilers js:babel/register spec/", - "cover": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --compilers js:babel/register --colors --reporter spec spec/", - "cover-es6": " node --harmony node_modules/istanbul-harmony/lib/cli.js cover --print both --hook-run-in-context node_modules/mocha/bin/_mocha -- -R spec --U exports --compilers js:babel/register spec/", - "lint": "npm run lint:lib && npm run lint:src&& npm run lint:spec", - "lint:spec": "jshint spec/", + "test": "mocha --compilers js:babel/register --colors --reporter spec", + "cover": "babel-node node_modules/isparta/bin/isparta cover node_modules/mocha/bin/_mocha --report lcovonly -- --colors --reporter spec", + "lint": "npm run lint:lib && npm run lint:src&& npm run lint:test", "lint:lib": "jshint lib/", "lint:src": "jshint src/", - "compile": "npm run compile:libs && npm run compile:src", + "lint:test": "jshint test/", + "compile": "npm run compile:lib && npm run compile:src", + "compile:lib": "babel -d compiled/lib/ lib/", "compile:src": "babel -d compiled/dist/ src/", - "compile:libs": "babel -d compiled/lib/ lib/", "prepublish": "npm run compile", - "build": "npm run lint && npm run test && npm run cover-es6", + "build": "npm run lint && npm run test && npm run cover", "post-build": "rm -rf coverage/" }, "repository": { @@ -36,8 +35,7 @@ "devDependencies": { "babel": "^5.8.23", "coveralls": "^2.11.4", - "istanbul": "^0.4.0", - "istanbul-harmony": "^0.3.16", + "isparta": "^3.1.0", "jshint": "^2.8.0", "mocha": "^2.3.3" }