computation
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,6 +0,5 @@ | ||
// A computation describes a way to compute a value out of the environment. | ||
// The value may not immediately be available (eg. if it's being asynchronously | ||
// fetched from a server). | ||
"use strict"; | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -10,4 +9,2 @@ value: true | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -24,4 +21,2 @@ | ||
key: "then", | ||
// Like the ES6 Promise#then function. | ||
value: function then(resolve, reject) { | ||
@@ -44,5 +39,2 @@ var _this = this; | ||
key: "fmap", | ||
// Map over the result. Pending state and errors are passsed onto the next | ||
// computation untounched. | ||
value: function fmap(f) { | ||
@@ -59,5 +51,2 @@ return this.then(function (v) { | ||
key: "bind", | ||
// Like fmap, but the function can return a computation which is then | ||
// automatically executed. | ||
value: function bind(f) { | ||
@@ -70,10 +59,14 @@ return this.fmap(function (v) { | ||
key: "get", | ||
// Get the result of this computation. If the result is not available yet, | ||
// return the fallback value. | ||
value: function get(fallback) { | ||
return this.getf(function () { | ||
return fallback; | ||
}); | ||
} | ||
}, { | ||
key: "getf", | ||
value: function getf(fallback) { | ||
try { | ||
var result = this.fn(); | ||
if (result === Computation.Pending) { | ||
return fallback; | ||
return fallback(); | ||
} else { | ||
@@ -83,3 +76,3 @@ return result; | ||
} catch (e) { | ||
return fallback; | ||
return fallback(); | ||
} | ||
@@ -89,4 +82,2 @@ } | ||
key: "pure", | ||
// Convenience functions to create pure and failing computations. | ||
value: function pure(value) { | ||
@@ -106,4 +97,2 @@ return new Computation(function () { | ||
key: "liftA2", | ||
// Pending computations and errors are passed through. | ||
value: function liftA2(a, b, f) { | ||
@@ -129,12 +118,7 @@ try { | ||
exports["default"] = Computation; | ||
exports.default = Computation; | ||
// Special value which can be used to denote that the computation is | ||
// pending and the result may become available at a later time. | ||
Computation.Pending = {}; | ||
// A predefined computation which is always pending. It is a property | ||
// rather than a function because it doesn't have to be parametrized. | ||
Computation.pending = new Computation(function () { | ||
return Computation.Pending; | ||
}); | ||
module.exports = exports["default"]; | ||
}); |
{ | ||
"name": "computation", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A small JavaScript library to express computations", | ||
"main": "computation.js", | ||
"typings": "computation.d.ts", | ||
"scripts": { | ||
"test": "./node_modules/.bin/gulp test" | ||
"test": "script/test" | ||
}, | ||
@@ -19,11 +20,15 @@ "repository": { | ||
"devDependencies": { | ||
"mocha": "*", | ||
"chai": "*", | ||
"typescript": "*", | ||
"gulp": "*", | ||
"gulp-tslint": "*", | ||
"gulp-typescript": "*", | ||
"gulp-mocha": "*", | ||
"gulp-babel": "*" | ||
"babel-preset-es2015": "^6.3.13", | ||
"chai": "^3.4.1", | ||
"gulp": "^3.9.0", | ||
"gulp-babel": "*", | ||
"gulp-mocha": "^2.2.0", | ||
"gulp-tslint": "^4.1.1", | ||
"gulp-typescript": "^2.9.2", | ||
"merge2": "^0.3.6", | ||
"mocha": "^2.3.4", | ||
"tsd": "^0.6.5", | ||
"tslint": "^3.1.1", | ||
"typescript": "^1.7.3" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5
119
10908
12