From 942e3c16b270d5be99a99380856c47a26961749f Mon Sep 17 00:00:00 2001 From: Aldwin Vlasblom Date: Tue, 7 Jan 2020 16:50:03 +0100 Subject: [PATCH] Release 12.1.0 New Features - #404 (323bdab) Add a 'pap' function: 'ap' in parallel Improvements - #404 (7b6d9fd) Improvements to debuggability of ConcurrentFuture related functions, and removal of an external dependency. - #410 (b465433) Mistake in TypeScript annotations fixed. - #404 (6aaf82d) Mistake in TypeScript annotations fixed. --- README.md | 2 +- dist/bundle.js | 346 ++++++++++--------------------------------------- package.json | 2 +- 3 files changed, 72 insertions(+), 278 deletions(-) diff --git a/README.md b/README.md index c5557e90..b5aff39c 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ getPackageName ('package.json') ### Global Bundle (CDN) Fluture is hosted in full with all of its dependencies at -https://cdn.jsdelivr.net/gh/fluture-js/Fluture@12.0.2/dist/bundle.js +https://cdn.jsdelivr.net/gh/fluture-js/Fluture@12.1.0/dist/bundle.js This script will add `Fluture` to the global scope. diff --git a/dist/bundle.js b/dist/bundle.js index 9395b626..7a625303 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -1,5 +1,5 @@ /** - * Fluture bundled; version 12.0.2 + * Fluture bundled; version 12.1.0 */ var Fluture = (function () { @@ -1879,20 +1879,20 @@ var Fluture = (function () { } var ParallelApTransformation = - createParallelTransformation('parallelAp', earlyCrash, earlyReject, noop, { + createParallelTransformation('pap', earlyCrash, earlyReject, noop, { resolved: function ParallelApTransformation$resolved(f){ if(isFunction(f)) return this.$1._transform(new MapTransformation(this.context, f)); throw typeError( - 'parallelAp expects the second Future to resolve to a Function\n' + + 'pap expects the second Future to resolve to a Function\n' + ' Actual: ' + sanctuaryShow(f) ); } }); - function parallelAp(mx){ - var context1 = application1(parallelAp, future, arguments); - return function parallelAp(mf){ - var context2 = application(2, parallelAp, future, arguments, context1); + function pap(mx){ + var context1 = application1(pap, future, arguments); + return function pap(mf){ + var context2 = application(2, pap, future, arguments, context1); return mf._transform(new ParallelApTransformation(context2, mx)); }; } @@ -1967,290 +1967,84 @@ var Fluture = (function () { }; } - var concurrify = createCommonjsModule(function (module) { - //. # Concurrify - //. - //. [![Chat](https://badges.gitter.im/fluture-js/concurrify.svg)](https://gitter.im/fluture-js/fluture) - //. [![NPM Version](https://badge.fury.io/js/concurrify.svg)](https://www.npmjs.com/package/concurrify) - //. [![Dependencies](https://david-dm.org/fluture-js/concurrify.svg)](https://david-dm.org/fluture-js/concurrify) - //. [![Build Status](https://travis-ci.org/fluture-js/concurrify.svg?branch=master)](https://travis-ci.org/fluture-js/concurrify) - //. [![Code Coverage](https://codecov.io/gh/fluture-js/concurrify/branch/master/graph/badge.svg)](https://codecov.io/gh/fluture-js/concurrify) - //. - //. Turn non-concurrent [FantasyLand 3][FL3] Applicatives concurrent. - //. - //. Most time-dependent applicatives are very useful as Monads, because it - //. gives them the ability to run sequentially, where each step depends on the - //. previous. However, they lose the ability to run concurrently. This library - //. allows one to wrap a [`Monad`][FL:Monad] (with sequential `ap`) in an - //. [`Alternative`][FL:Alternative] (with parallel `ap`). - //. - //. ## Usage - //. - //. ```js - //. // The concurrify function takes four arguments, explained below. - //. const concurrify = require ('concurrify'); - //. - //. // The Type Representative of the Applicative we want to transform. - //. const Future = require ('fluture'); - //. - //. // A "zero" instance and an "alt" function for "Alternative". - //. const zero = Future (() => {}); - //. const alt = Future.race; - //. - //. // An override "ap" function that runs the Applicatives concurrently. - //. const ap = (mx, mf) => (Future.both (mx, mf)).map (([x, f]) => f (x)); - //. - //. // A new Type Representative created by concurrify. - //. const ConcurrentFuture = concurrify (Future, zero, alt, ap); - //. - //. // We can use our type as such: - //. const par = ConcurrentFuture (Future.of (1)); - //. const seq = par.sequential; - //. seq.fork (console.error, console.log); - //. ``` - //. - //. ## Interoperability - //. - //. * Implements [FantasyLand 3][FL3] `Alternative` - //. (`of`, `zero`, `map`, `ap`, `alt`). - //. * Instances can be identified by, and are compared using, - //. [Sanctuary Type Identifiers][STI]. - //. * Instances can be converted to String representations according to - //. [Sanctuary Show][SS]. - //. - //. ## API - (function(f) { - - /* istanbul ignore next */ - { - module.exports = f ( - sanctuaryShow, - sanctuaryTypeIdentifiers - ); - } - - } (function(show, type) { - - var $alt = 'fantasy-land/alt'; - var $ap = 'fantasy-land/ap'; - var $map = 'fantasy-land/map'; - var $of = 'fantasy-land/of'; - var $zero = 'fantasy-land/zero'; - var $$type = '@@type'; - var $$show = '@@show'; - var ordinal = ['first', 'second', 'third', 'fourth', 'fifth']; - - // isFunction :: Any -> Boolean - function isFunction(f) { - return typeof f === 'function'; - } - - // isBinary :: Function -> Boolean - function isBinary(f) { - return f.length >= 2; - } - - // isApplicativeRepr :: TypeRepr -> Boolean - function isApplicativeRepr(Repr) { - return typeof Repr[$of] === 'function' && - typeof Repr[$of] ()[$ap] === 'function'; - } - - // invalidArgument :: (String, Number, String, String) -> !Undefined - function invalidArgument(it, at, expected, actual) { - throw new TypeError ( - it - + ' expects its ' - + ordinal[at] - + ' argument to ' - + expected - + '\n Actual: ' - + show (actual) - ); - } - - // invalidContext :: (String, String, String) -> !Undefined - function invalidContext(it, actual, an) { - throw new TypeError ( - it - + ' was invoked outside the context of a ' - + an - + '. \n Called on: ' - + show (actual) - ); - } - - // getTypeIdentifier :: TypeRepresentative -> String - function getTypeIdentifier(Repr) { - return Repr[$$type] || Repr.name || 'Anonymous'; - } - - // generateTypeIdentifier :: String -> String - function generateTypeIdentifier(identifier) { - var o = type.parse (identifier); - return ( - (o.namespace || 'concurrify') + '/Concurrent' + o.name + '@' + o.version - ); - } - - //# concurrify :: (Applicative f, Alternative (m f)) => (TypeRep f, f a, (f a, f a) -> f a, (f a, f (a -> b)) -> f b) -> f c -> m f c - return function concurrify(Repr, zero, alt, ap) { - - var INNERTYPE = getTypeIdentifier (Repr); - var OUTERTYPE = generateTypeIdentifier (INNERTYPE); - var INNERNAME = (type.parse (INNERTYPE)).name; - var OUTERNAME = (type.parse (OUTERTYPE)).name; - - function Concurrently(sequential) { - this.sequential = sequential; - } - - function isInner(x) { - return ( - (x instanceof Repr) || - (Boolean (x) && x.constructor === Repr) || - (type (x) === Repr[$$type]) - ); - } - - function isOuter(x) { - return ( - (x instanceof Concurrently) || - (Boolean (x) && x.constructor === Concurrently) || - (type (x) === OUTERTYPE) - ); - } - - function construct(x) { - if (!isInner (x)) { - invalidArgument (OUTERNAME, 0, 'be of type "' + INNERNAME + '"', x); - } - return new Concurrently (x); - } - - if (!isApplicativeRepr (Repr)) { - invalidArgument ('concurrify', 0, 'represent an Applicative', Repr); - } - - if (!isInner (zero)) { - invalidArgument - ('concurrify', 1, 'be of type "' + INNERNAME + '"', zero); - } - - if (!isFunction (alt)) { - invalidArgument ('concurrify', 2, 'be a function', alt); - } - - if (!isBinary (alt)) { - invalidArgument ('concurrify', 2, 'be binary', alt); - } - - if (!isFunction (ap)) { - invalidArgument ('concurrify', 3, 'be a function', ap); - } - - if (!isBinary (ap)) { - invalidArgument ('concurrify', 3, 'be binary', ap); - } - - var proto = - Concurrently.prototype = - construct.prototype = {constructor: construct}; - - proto[$$type] = OUTERTYPE; - construct[$$type] = OUTERTYPE; - - var mzero = new Concurrently (zero); - - construct[$zero] = function Concurrently$zero() { - return mzero; - }; - - construct[$of] = function Concurrently$of(value) { - return new Concurrently (Repr[$of] (value)); - }; - - proto[$map] = function Concurrently$map(mapper) { - if (!isOuter (this)) { - invalidContext (OUTERNAME + '#map', this, OUTERNAME); - } - - if (!isFunction (mapper)) { - invalidArgument (OUTERNAME + '#map', 0, 'be a function', mapper); - } - - return new Concurrently (this.sequential[$map] (mapper)); - }; - - proto[$ap] = function Concurrently$ap(m) { - if (!isOuter (this)) { - invalidContext (OUTERNAME + '#ap', this, OUTERNAME); - } - - if (!isOuter (m)) { - invalidArgument (OUTERNAME + '#ap', 0, 'be a ' + OUTERNAME, m); - } + var RaceTransformation = + createParallelTransformation('race', earlyCrash, earlyReject, earlyResolve, {}); - return new Concurrently (ap (this.sequential, m.sequential)); - }; + function race(left){ + var context1 = application1(race, future, arguments); + return function race(right){ + var context2 = application(2, race, future, arguments, context1); + return right._transform(new RaceTransformation(context2, left)); + }; + } - proto[$alt] = function Concurrently$alt(m) { - if (!isOuter (this)) { - invalidContext (OUTERNAME + '#alt', this, OUTERNAME); - } + function ConcurrentFuture (sequential){ + this.sequential = sequential; + } - if (!isOuter (m)) { - invalidArgument (OUTERNAME + '#alt', 0, 'be a ' + OUTERNAME, m); - } + ConcurrentFuture.prototype = Object.create(Par.prototype); - return new Concurrently (alt (this.sequential, m.sequential)); - }; + function Par (sequential){ + if(!isFuture(sequential)) throw invalidFutureArgument(Par.name, 0, sequential); + return new ConcurrentFuture(sequential); + } - proto[$$show] = function Concurrently$show() { - return OUTERNAME + '(' + show (this.sequential) + ')'; - }; + var $$type$1 = namespace + '/ConcurrentFuture@' + version; + var zeroInstance = new ConcurrentFuture(never); - proto.toString = function Concurrently$toString() { - if (!isOuter (this)) { - invalidContext (OUTERNAME + '#toString', this, OUTERNAME); - } - return this[$$show] (); - }; + Par['@@type'] = $$type$1; - return construct; + Par[FL.of] = function Par$of(x){ + return new ConcurrentFuture(resolve(x)); + }; - }; + Par[FL.zero] = function Par$zero(){ + return zeroInstance; + }; - })); + Par.prototype['@@type'] = $$type$1; - //. [FL3]: https://github.com/fantasyland/fantasy-land/ - //. [FL:Monad]: https://github.com/fantasyland/fantasy-land/#monad - //. [FL:Alternative]: https://github.com/fantasyland/fantasy-land/#alternative - //. [STI]: https://github.com/sanctuary-js/sanctuary-type-identifiers - //. [SS]: https://github.com/sanctuary-js/sanctuary-show - }); + Par.prototype['@@show'] = function Par$show(){ + return this.toString(); + }; - var RaceTransformation = - createParallelTransformation('race', earlyCrash, earlyReject, earlyResolve, {}); + Par.prototype.toString = function Par$toString(){ + return 'Par (' + this.sequential.toString() + ')'; + }; - function race(left){ - var context1 = application1(race, future, arguments); - return function race(right){ - var context2 = application(2, race, future, arguments, context1); - return right._transform(new RaceTransformation(context2, left)); - }; - } + Par.prototype[FL.map] = function Par$FL$map(f){ + var context = captureContext( + nil, + 'a Fantasy Land dispatch to map via ConcurrentFuture', + Par$FL$map + ); + return new ConcurrentFuture(this.sequential._transform(new MapTransformation(context, f))); + }; - function uncurry(f){ - return function(a, b){ - return f(a)(b); - }; - } + Par.prototype[FL.ap] = function Par$FL$ap(other){ + var context = captureContext( + nil, + 'a Fantasy Land dispatch to ap via ConcurrentFuture', + Par$FL$ap + ); + return new ConcurrentFuture(other.sequential._transform( + new ParallelApTransformation(context, this.sequential) + )); + }; - var Par = concurrify(Future, never, uncurry(race), uncurry(parallelAp)); + Par.prototype[FL.alt] = function Par$FL$alt(other){ + var context = captureContext( + nil, + 'a Fantasy Land dispatch to alt via ConcurrentFuture', + Par$FL$alt + ); + return new ConcurrentFuture(other.sequential._transform( + new RaceTransformation(context, this.sequential) + )); + }; function isParallel(x){ - return x instanceof Par || sanctuaryTypeIdentifiers(x) === Par['@@type']; + return x instanceof ConcurrentFuture || sanctuaryTypeIdentifiers(x) === $$type$1; } function promise(m){ @@ -2354,7 +2148,7 @@ var Fluture = (function () { mapRej: mapRej, map: map, node: node, - parallelAp: parallelAp, + pap: pap, parallel: parallel, Par: Par, promise: promise, diff --git a/package.json b/package.json index 78a60d29..90d4a078 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fluture", - "version": "12.0.2", + "version": "12.1.0", "description": "FantasyLand compliant (monadic) alternative to Promises", "main": "index.cjs", "type": "module",