Comparing version 7.2.0 to 7.2.1
247
index.js
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('sanctuary-type-classes'), require('inspect-f'), require('sanctuary-type-identifiers'), require('denque'), require('concurrify')) : | ||
typeof define === 'function' && define.amd ? define(['sanctuary-type-classes', 'inspect-f', 'sanctuary-type-identifiers', 'denque', 'concurrify'], factory) : | ||
(global.Fluture = factory(global.sanctuaryTypeClasses,global.inspectf,global.sanctuaryTypeIdentifiers,global.Denque,global.concurrify)); | ||
}(this, (function (Z,inspectf,type,Denque,concurrify) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('sanctuary-type-classes'), require('inspect-f'), require('sanctuary-type-identifiers'), require('concurrify'), require('denque')) : | ||
typeof define === 'function' && define.amd ? define(['sanctuary-type-classes', 'inspect-f', 'sanctuary-type-identifiers', 'concurrify', 'denque'], factory) : | ||
(global.Fluture = factory(global.sanctuaryTypeClasses,global.inspectf,global.sanctuaryTypeIdentifiers,global.concurrify,global.Denque)); | ||
}(this, (function (Z,inspectf,type,concurrify,Denque) { 'use strict'; | ||
@@ -10,4 +10,4 @@ Z = Z && Z.hasOwnProperty('default') ? Z['default'] : Z; | ||
type = type && type.hasOwnProperty('default') ? type['default'] : type; | ||
concurrify = concurrify && concurrify.hasOwnProperty('default') ? concurrify['default'] : concurrify; | ||
Denque = Denque && Denque.hasOwnProperty('default') ? Denque['default'] : Denque; | ||
concurrify = concurrify && concurrify.hasOwnProperty('default') ? concurrify['default'] : concurrify; | ||
@@ -307,3 +307,3 @@ function setImmediate$1(f, x){ return setTimeout(f, 0, x) } | ||
function Future$1(computation){ | ||
function Future(computation){ | ||
if(!isFunction(computation)) invalidArgument('Future', 0, 'be a Function', computation); | ||
@@ -314,6 +314,24 @@ return new Computation(computation); | ||
function isFuture(x){ | ||
return x instanceof Future$1 || type(x) === $$type; | ||
return x instanceof Future || type(x) === $$type; | ||
} | ||
Future$1.prototype.ap = function Future$ap(other){ | ||
Future['@@type'] = $$type; | ||
Future.prototype[FL.ap] = function Future$FL$ap(other){ | ||
return other._ap(this); | ||
}; | ||
Future.prototype[FL.map] = function Future$FL$map(mapper){ | ||
return this._map(mapper); | ||
}; | ||
Future.prototype[FL.bimap] = function Future$FL$bimap(lmapper, rmapper){ | ||
return this._bimap(lmapper, rmapper); | ||
}; | ||
Future.prototype[FL.chain] = function Future$FL$chain(mapper){ | ||
return this._chain(mapper); | ||
}; | ||
Future.prototype.ap = function Future$ap(other){ | ||
if(!isFuture(this)) invalidContext('Future#ap', this); | ||
@@ -324,3 +342,3 @@ if(!isFuture(other)) invalidFuture('Future#ap', 0, other); | ||
Future$1.prototype.map = function Future$map(mapper){ | ||
Future.prototype.map = function Future$map(mapper){ | ||
if(!isFuture(this)) invalidContext('Future#map', this); | ||
@@ -331,3 +349,3 @@ if(!isFunction(mapper)) invalidArgument('Future#map', 0, 'to be a Function', mapper); | ||
Future$1.prototype.bimap = function Future$bimap(lmapper, rmapper){ | ||
Future.prototype.bimap = function Future$bimap(lmapper, rmapper){ | ||
if(!isFuture(this)) invalidContext('Future#bimap', this); | ||
@@ -339,3 +357,3 @@ if(!isFunction(lmapper)) invalidArgument('Future#bimap', 0, 'to be a Function', lmapper); | ||
Future$1.prototype.chain = function Future$chain(mapper){ | ||
Future.prototype.chain = function Future$chain(mapper){ | ||
if(!isFuture(this)) invalidContext('Future#chain', this); | ||
@@ -346,3 +364,3 @@ if(!isFunction(mapper)) invalidArgument('Future#chain', 0, 'to be a Function', mapper); | ||
Future$1.prototype.mapRej = function Future$mapRej(mapper){ | ||
Future.prototype.mapRej = function Future$mapRej(mapper){ | ||
if(!isFuture(this)) invalidContext('Future#mapRej', this); | ||
@@ -353,3 +371,3 @@ if(!isFunction(mapper)) invalidArgument('Future#mapRej', 0, 'to be a Function', mapper); | ||
Future$1.prototype.chainRej = function Future$chainRej(mapper){ | ||
Future.prototype.chainRej = function Future$chainRej(mapper){ | ||
if(!isFuture(this)) invalidContext('Future#chainRej', this); | ||
@@ -360,3 +378,3 @@ if(!isFunction(mapper)) invalidArgument('Future#chainRej', 0, 'to be a Function', mapper); | ||
Future$1.prototype.race = function Future$race(other){ | ||
Future.prototype.race = function Future$race(other){ | ||
if(!isFuture(this)) invalidContext('Future#race', this); | ||
@@ -367,3 +385,3 @@ if(!isFuture(other)) invalidFuture('Future#race', 0, other); | ||
Future$1.prototype.both = function Future$both(other){ | ||
Future.prototype.both = function Future$both(other){ | ||
if(!isFuture(this)) invalidContext('Future#both', this); | ||
@@ -374,3 +392,3 @@ if(!isFuture(other)) invalidFuture('Future#both', 0, other); | ||
Future$1.prototype.and = function Future$and(other){ | ||
Future.prototype.and = function Future$and(other){ | ||
if(!isFuture(this)) invalidContext('Future#and', this); | ||
@@ -381,3 +399,3 @@ if(!isFuture(other)) invalidFuture('Future#and', 0, other); | ||
Future$1.prototype.or = function Future$or(other){ | ||
Future.prototype.or = function Future$or(other){ | ||
if(!isFuture(this)) invalidContext('Future#or', this); | ||
@@ -388,3 +406,3 @@ if(!isFuture(other)) invalidFuture('Future#or', 0, other); | ||
Future$1.prototype.swap = function Future$swap(){ | ||
Future.prototype.swap = function Future$swap(){ | ||
if(!isFuture(this)) invalidContext('Future#ap', this); | ||
@@ -394,3 +412,3 @@ return this._swap(); | ||
Future$1.prototype.fold = function Future$fold(lmapper, rmapper){ | ||
Future.prototype.fold = function Future$fold(lmapper, rmapper){ | ||
if(!isFuture(this)) invalidContext('Future#ap', this); | ||
@@ -402,3 +420,3 @@ if(!isFunction(lmapper)) invalidArgument('Future#fold', 0, 'to be a Function', lmapper); | ||
Future$1.prototype.finally = function Future$finally(other){ | ||
Future.prototype.finally = function Future$finally(other){ | ||
if(!isFuture(this)) invalidContext('Future#finally', this); | ||
@@ -409,3 +427,3 @@ if(!isFuture(other)) invalidFuture('Future#finally', 0, other); | ||
Future$1.prototype.lastly = function Future$lastly(other){ | ||
Future.prototype.lastly = function Future$lastly(other){ | ||
if(!isFuture(this)) invalidContext('Future#lastly', this); | ||
@@ -416,3 +434,3 @@ if(!isFuture(other)) invalidFuture('Future#lastly', 0, other); | ||
Future$1.prototype.fork = function Future$fork(rej, res){ | ||
Future.prototype.fork = function Future$fork(rej, res){ | ||
if(!isFuture(this)) invalidContext('Future#fork', this); | ||
@@ -424,3 +442,3 @@ if(!isFunction(rej)) invalidArgument('Future#fork', 0, 'to be a Function', rej); | ||
Future$1.prototype.value = function Future$value(res){ | ||
Future.prototype.value = function Future$value(res){ | ||
if(!isFuture(this)) invalidContext('Future#value', this); | ||
@@ -431,3 +449,3 @@ if(!isFunction(res)) invalidArgument('Future#value', 0, 'to be a Function', res); | ||
Future$1.prototype.done = function Future$done(callback){ | ||
Future.prototype.done = function Future$done(callback){ | ||
if(!isFuture(this)) invalidContext('Future#done', this); | ||
@@ -439,3 +457,3 @@ if(!isFunction(callback)) invalidArgument('Future#done', 0, 'to be a Function', callback); | ||
Future$1.prototype.promise = function Future$promise(){ | ||
Future.prototype.promise = function Future$promise(){ | ||
var _this = this; | ||
@@ -447,23 +465,23 @@ return new Promise(function Future$promise$computation(res, rej){ | ||
Future$1.prototype.isRejected = function Future$isRejected(){ | ||
Future.prototype.isRejected = function Future$isRejected(){ | ||
return false; | ||
}; | ||
Future$1.prototype.isResolved = function Future$isResolved(){ | ||
Future.prototype.isResolved = function Future$isResolved(){ | ||
return false; | ||
}; | ||
Future$1.prototype.isSettled = function Future$isSettled(){ | ||
Future.prototype.isSettled = function Future$isSettled(){ | ||
return this.isRejected() || this.isResolved(); | ||
}; | ||
Future$1.prototype.extractLeft = function Future$extractLeft(){ | ||
Future.prototype.extractLeft = function Future$extractLeft(){ | ||
return []; | ||
}; | ||
Future$1.prototype.extractRight = function Future$extractRight(){ | ||
Future.prototype.extractRight = function Future$extractRight(){ | ||
return []; | ||
}; | ||
var Core = Object.create(Future$1.prototype); | ||
var Core = Object.create(Future.prototype); | ||
@@ -663,3 +681,3 @@ Core._ap = function Core$ap(other){ | ||
Never.prototype = Object.create(Future$1.prototype); | ||
Never.prototype = Object.create(Future.prototype); | ||
@@ -955,3 +973,3 @@ Never.prototype._ap = moop; | ||
Sequence.prototype = Object.create(Future$1.prototype); | ||
Sequence.prototype = Object.create(Future.prototype); | ||
@@ -1307,31 +1325,52 @@ Sequence.prototype._transform = function Sequence$_transform(action){ | ||
Future$1['@@type'] = $$type; | ||
Future$1[FL.of] = Future$1.of = of; | ||
Future$1[FL.chainRec] = Future$1.chainRec = chainRec; | ||
Future$1.reject = reject; | ||
function check$ap$f(f){ | ||
if(!isFunction(f)) typeError( | ||
'Future#ap expects its first argument to be a Future of a Function' | ||
+ '\n Actual: Future.of(' + show(f) + ')' | ||
); | ||
} | ||
Future$1.ap = ap; | ||
function ParallelAp(mval, mfunc){ | ||
this._mval = mval; | ||
this._mfunc = mfunc; | ||
} | ||
Future$1.prototype[FL.ap] = function Future$FL$ap(other){ | ||
return other._ap(this); | ||
}; | ||
ParallelAp.prototype = Object.create(Core); | ||
Future$1.map = map; | ||
ParallelAp.prototype._fork = function ParallelAp$fork(rej, res){ | ||
var func, val, okval = false, okfunc = false, rejected = false, c1, c2; | ||
Future$1.prototype[FL.map] = function Future$FL$map(mapper){ | ||
return this._map(mapper); | ||
}; | ||
function ParallelAp$rej(x){ | ||
if(!rejected){ | ||
rejected = true; | ||
rej(x); | ||
} | ||
} | ||
Future$1.bimap = bimap; | ||
c1 = this._mval._fork(ParallelAp$rej, function ParallelAp$fork$resVal(x){ | ||
c1 = noop; | ||
if(!okval) return void (okfunc = true, val = x); | ||
res(func(x)); | ||
}); | ||
c2 = this._mfunc._fork(ParallelAp$rej, function ParallelAp$fork$resFunc(f){ | ||
c2 = noop; | ||
check$ap$f(f); | ||
if(!okfunc) return void (okval = true, func = f); | ||
res(f(val)); | ||
}); | ||
Future$1.prototype[FL.bimap] = function Future$FL$bimap(lmapper, rmapper){ | ||
return this._bimap(lmapper, rmapper); | ||
return function ParallelAp$fork$cancel(){ | ||
c1(); | ||
c2(); | ||
}; | ||
}; | ||
Future$1.chain = chain; | ||
Future$1.prototype[FL.chain] = function Future$FL$chain(mapper){ | ||
return this._chain(mapper); | ||
ParallelAp.prototype.toString = function ParallelAp$toString(){ | ||
return 'new ParallelAp(' + this._mval.toString() + ', ' + this._mfunc.toString() + ')'; | ||
}; | ||
function parallelAp(mval, mfunc){ | ||
return new ParallelAp(mval, mfunc); | ||
} | ||
function After$race(other){ | ||
@@ -1977,3 +2016,3 @@ return other.isSettled() | ||
Go.prototype.toString = function Go$toString(){ | ||
return `Future.do(${showf(this._generator)})`; | ||
return 'Future.do(' + showf(this._generator) + ')'; | ||
}; | ||
@@ -2115,67 +2154,2 @@ | ||
function check$ap$f(f){ | ||
if(!isFunction(f)) typeError( | ||
'Future#ap expects its first argument to be a Future of a Function' | ||
+ '\n Actual: Future.of(' + show(f) + ')' | ||
); | ||
} | ||
function ParallelAp(mval, mfunc){ | ||
this._mval = mval; | ||
this._mfunc = mfunc; | ||
} | ||
ParallelAp.prototype = Object.create(Core); | ||
ParallelAp.prototype._fork = function ParallelAp$fork(rej, res){ | ||
var func, val, okval = false, okfunc = false, rejected = false, c1, c2; | ||
function ParallelAp$rej(x){ | ||
if(!rejected){ | ||
rejected = true; | ||
rej(x); | ||
} | ||
} | ||
c1 = this._mval._fork(ParallelAp$rej, function ParallelAp$fork$resVal(x){ | ||
c1 = noop; | ||
if(!okval) return void (okfunc = true, val = x); | ||
res(func(x)); | ||
}); | ||
c2 = this._mfunc._fork(ParallelAp$rej, function ParallelAp$fork$resFunc(f){ | ||
c2 = noop; | ||
check$ap$f(f); | ||
if(!okfunc) return void (okval = true, func = f); | ||
res(f(val)); | ||
}); | ||
return function ParallelAp$fork$cancel(){ | ||
c1(); | ||
c2(); | ||
}; | ||
}; | ||
ParallelAp.prototype.toString = function ParallelAp$toString(){ | ||
return 'new ParallelAp(' + this._mval.toString() + ', ' + this._mfunc.toString() + ')'; | ||
}; | ||
var Par = concurrify(Future$1, never, race, function pap(mval, mfunc){ | ||
return new ParallelAp(mval, mfunc); | ||
}); | ||
Par.of = Par[FL.of]; | ||
Par.zero = Par[FL.zero]; | ||
Par.map = map; | ||
Par.ap = ap; | ||
Par.alt = alt; | ||
function isParallel(x){ | ||
return x instanceof Par || type(x) === Par['@@type']; | ||
} | ||
function seq(par){ | ||
if(!isParallel(par)) invalidArgument('Future.seq', 0, 'to be a Par', par); | ||
return par.sequential; | ||
} | ||
function check$parallel(m, i){ | ||
@@ -2283,3 +2257,3 @@ return isFuture(m) ? m : invalidFuture( | ||
TryP.prototype.toString = function TryP$toString(){ | ||
return `Future.tryP(${show(this._fn)})`; | ||
return 'Future.tryP(' + show(this._fn) + ')'; | ||
}; | ||
@@ -2296,8 +2270,35 @@ | ||
Future.of = Future[FL.of] = of; | ||
Future.chainRec = Future[FL.chainRec] = chainRec; | ||
Future.reject = reject; | ||
Future.ap = ap; | ||
Future.map = map; | ||
Future.bimap = bimap; | ||
Future.chain = chain; | ||
var Par = concurrify(Future, never, race, parallelAp); | ||
Par.of = Par[FL.of]; | ||
Par.zero = Par[FL.zero]; | ||
Par.map = map; | ||
Par.ap = ap; | ||
Par.alt = alt; | ||
function isParallel(x){ | ||
return x instanceof Par || type(x) === Par['@@type']; | ||
} | ||
function seq(par){ | ||
if(!isParallel(par)) invalidArgument('Future.seq', 0, 'to be a Par', par); | ||
return par.sequential; | ||
} | ||
var Fluture = Object.freeze({ | ||
default: Future$1, | ||
Future: Future$1, | ||
Future: Future, | ||
default: Future, | ||
Par: Par, | ||
isParallel: isParallel, | ||
seq: seq, | ||
isFuture: isFuture, | ||
@@ -2326,4 +2327,2 @@ reject: reject, | ||
node: node, | ||
Par: Par, | ||
seq: seq, | ||
parallel: parallel, | ||
@@ -2354,3 +2353,3 @@ tryP: tryP, | ||
var index_cjs = Object.assign(Future$1, Fluture); | ||
var index_cjs = Object.assign(Future, Fluture); | ||
@@ -2357,0 +2356,0 @@ return index_cjs; |
{ | ||
"name": "fluture", | ||
"version": "7.2.0", | ||
"version": "7.2.1", | ||
"description": "FantasyLand compliant (monadic) alternative to Promises", | ||
@@ -25,3 +25,3 @@ "main": "index.js", | ||
"test": "npm run lint && npm run lint:readme && npm run test:unit", | ||
"test:unit": "npm run build && nyc mocha --require @std/esm --ui bdd --reporter list --check-leaks --full-trace test/**.test.js", | ||
"test:unit": "npm run build && nyc --include src mocha --require @std/esm --ui bdd --reporter list --check-leaks --full-trace test/**.test.js", | ||
"test:coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov" | ||
@@ -65,6 +65,6 @@ }, | ||
"devDependencies": { | ||
"@std/esm": "^0.12.1", | ||
"@std/esm": "0.12.1", | ||
"benchmark": "^2.1.0", | ||
"chai": "^4.1.2", | ||
"codecov": "^2.2.0", | ||
"codecov": "^3.0.0", | ||
"data.task": "^3.0.0", | ||
@@ -71,0 +71,0 @@ "eslint": "^4.7.2", |
import {show, showf, noop, moop} from './internal/fn'; | ||
import {isFunction} from './internal/is'; | ||
import {error, typeError, invalidArgument, invalidContext, invalidFuture} from './internal/throw'; | ||
import {$$type} from './internal/const'; | ||
import {FL, $$type} from './internal/const'; | ||
import interpreter from './internal/interpreter'; | ||
@@ -22,2 +22,20 @@ import {empty as emptyList, cons} from './internal/list'; | ||
Future['@@type'] = $$type; | ||
Future.prototype[FL.ap] = function Future$FL$ap(other){ | ||
return other._ap(this); | ||
}; | ||
Future.prototype[FL.map] = function Future$FL$map(mapper){ | ||
return this._map(mapper); | ||
}; | ||
Future.prototype[FL.bimap] = function Future$FL$bimap(lmapper, rmapper){ | ||
return this._bimap(lmapper, rmapper); | ||
}; | ||
Future.prototype[FL.chain] = function Future$FL$chain(mapper){ | ||
return this._chain(mapper); | ||
}; | ||
Future.prototype.ap = function Future$ap(other){ | ||
@@ -24,0 +42,0 @@ if(!isFuture(this)) invalidContext('Future#ap', this); |
@@ -73,3 +73,3 @@ /*eslint consistent-return: 0*/ | ||
Go.prototype.toString = function Go$toString(){ | ||
return `Future.do(${showf(this._generator)})`; | ||
return 'Future.do(' + showf(this._generator) + ')'; | ||
}; | ||
@@ -76,0 +76,0 @@ |
@@ -36,3 +36,3 @@ import {Core} from './core'; | ||
TryP.prototype.toString = function TryP$toString(){ | ||
return `Future.tryP(${show(this._fn)})`; | ||
return 'Future.tryP(' + show(this._fn) + ')'; | ||
}; | ||
@@ -39,0 +39,0 @@ |
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
204639
57
4103