From 9660ff0a510a1caf26deca05c5a9ad0124d2b40f Mon Sep 17 00:00:00 2001 From: Richboy David Date: Mon, 7 Aug 2017 22:26:51 -0400 Subject: [PATCH] Added minified version --- richflow.js | 4 ++-- richflow.min.js | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 richflow.min.js diff --git a/richflow.js b/richflow.js index a2b0720..73ef616 100644 --- a/richflow.js +++ b/richflow.js @@ -1766,7 +1766,7 @@ var seenNull = false, item; for (let i = 0; i < this.span; i++) { if (seenNull) - toAdd.add(null); + toAdd.push(null); else { item = iteratorFlow.process(); toAdd.push(item); @@ -1831,7 +1831,7 @@ var seenNull = false, item; for (let i = 0; i < this.span; i++) { if (seenNull) - toAdd.add(null); + toAdd.push(null); else { item = iteratorFlow.process(); toAdd.push(item); diff --git a/richflow.min.js b/richflow.min.js new file mode 100644 index 0000000..0eef33b --- /dev/null +++ b/richflow.min.js @@ -0,0 +1 @@ +"use strict";(function(t,n){if("object"==typeof exports&&exports)n(exports);else{var s={};n(s),"function"==typeof define&&define.amd?define(s):t.RichFlow=s}})(this,function(t){function n(L,I){I.prev=L,L.next=I,I.rootFlow=L.rootFlow}function s(L,I){var k=function(O){setTimeout(()=>I._prePush(O,L),0)};L.subscribe(k),I.subscribers[L.key]=k}function o(L,I){I.subscribers[L.key]&&(L.unsubscribe(I.subscribers[L.key]),delete I.subscribers[L.key])}function u(L){var I;if(A.isNumber(L))I=function(k){var P=0;return{isDataEnd:function(){try{return!(P=L.length&&(L=L.slice(I),I=0),k}},this.peek=function(){return 0L,this.rootFlow=null,this.terminalFunc=()=>{},this.isDiscretized=!1,this.elements=[],this.ended=!1,this.elemPos=0}process(){if(this.ended)return this._getElement();this.prev.next!=this&&(this.prev.next=this);var L=this.prev.process();return null==L&&this._addElement(null),L}startPush(){this.prev.startPush()}stopPush(){this.prev.stopPush()}reset(){this.ended=!1,this.elements=[]}pipe(L){var I=this.pipeFunc(L);return this._addElement(I),null===this.next?I:this.next.pipe(I)}push(L){var I=this.pipeFunc(L);null===this.next?this.terminalFunc(I):this.next.push(I)}setTerminalFunction(L){A.isFunction(L)&&(this.terminalFunc=L)}static from(L){return j.getFlow(L)}static of(){return 0==arguments.length?j.getFlow([]):1k+L))}static fromFile(L){return new f(j.createIteratorFromFileSystem(L))}static toArray(){return"toArray"}static toSet(){return"toSet"}static ASC(){return"ASC"}static DESC(){return"DESC"}static NUM_ASC(){return"NUM_ASC"}static NUM_DESC(){return"NUM_DESC"}limit(L){if(0>=L)throw new Error("Limit value must be greater than 0");var I=new x(0,L);return n(this,I),I}skip(L){if(0>=L)throw new Error("Skip value must be greater than 0");var I=new x(L,Number.MAX_VALUE);return n(this,I),I}skipUntil(L){if(!A.isFunction(L))throw new Error("skipUntil requires a function");var I=new y(L,1);return n(this,I),I}skipWhile(L){if(!A.isFunction(L))throw new Error("skipWhile requires a function");var I=new y(L,2);return n(this,I),I}takeUntil(L){if(!A.isFunction(L))throw new Error("takeUntil requires a function");var I=new y(L,3);return n(this,I),I}takeWhile(L){if(!A.isFunction(L))throw new Error("takeWhile requires a function");var I=new y(L,4);return n(this,I),I}range(L,I){if(0>L)throw new Error("Start Index cannot be negative");if(0>=I)throw new Error("End Index must be greater than 0");if(L>I)throw new Error("End Index cannot be less than Start Index");var k=new x(L,I);return n(this,k),k}select(L){var I=new m;return I.pipeFunc=A.isFunction(L)?L:function(k){return k[L]},n(this,I),I}map(L){return this.select(L)}selectExpand(L){var I=new h(L);return n(this,I),I}selectFlatten(){return this.selectExpand(L=>L)}where(L){var I=new g(L);return n(this,I),I}filter(L){return this.where(L)}static _sort(L){return function(I,k){return"num_asc"==L?I-k:"num_desc"==L?k-I:Ik?"asc"==L?1:-1:0}}orderBy(L){L||(L=m._sort("asc")),A.isFunction(L)?L==m.ASC?L=m._sort("asc"):L==m.DESC?L=m._sort("desc"):L==m.NUM_ASC?L=m._sort("num_asc"):L==m.NUM_DESC&&(L=m._sort("num_desc")):A.isString(L)&&(L=m._sort(L.toLowerCase()));var I=new F(L);return n(this,I),I}partitionBy(L){var I=L;A.isFunction(L)||(I=function(O){return O[L]});var k=new E(I);return n(this,k),k}discretize(L,I,k){void 0===k&&(k=!0);var O=new S(L,u(I),k);return n(this,O),this.isDiscretized=!0,O}count(){var I,k,L=0;for(k=this.next,this.next=null;null!=(I=this.process());)L++;return this.next=k,L}static toMap(L){var I=L;return A.isFunction(L)||(I=function(k){return k[L]}),I}_toSet(){var I,k,L=new Set;for(k=this.next,this.next=null;null!=(I=this.process());)L.add(I);return this.next=k,L}_toArray(){var I,k,L=[];for(k=this.next,this.next=null;null!=(I=this.process());)L.push(I);return this.next=k,L}groupBy(L){var I=L;A.isFunction(L)||(I=function(C){return C[L]});var k,O,M,P={};for(M=this.next,this.next=null;null!=(k=this.process());)O=I(k),P[O]||(P[O]=[]),P[O].push(k);return this.next=M,P}join(L){L||(L=",");var O,P,I="",k=0;for(P=this.next,this.next=null;null!=(O=this.process());)0k.set(O.key,O.value)),k}return this._toArray()}foreach(L){var I,k;for(k=this.next,this.next=null;null!=(I=this.process());)L(I);this.next=k}forEach(L){this.foreach(L)}anyMatch(L){var I,k;for(k=this.next,this.next=null;null!=(I=this.process());)if(L(I))return!0;return this.next=k,!1}allMatch(L){var I,k;for(k=this.next,this.next=null;null!=(I=this.process());)if(!L(I))return!1;return this.next=k,!0}noneMatch(L){return!this.anyMatch(L)}findFirst(){var L,I;return I=this.next,this.next=null,L=this.process(),this.next=I,L}findAny(){return this.findFirst()}findLast(){var L,k,I=null;for(k=this.next,this.next=null;null!=(L=this.process());)I=L;return this.next=k,I}sum(){var L,k,I=0;for(k=this.next,this.next=null;null!=(L=this.process());)I+=L;return this.next=k,I}max(){var L,k,I=null;for(k=this.next,this.next=null;null!=(L=this.process());)(null==I||L>I)&&(I=L);return this.next=k,I}min(){var L,k,I=null;for(k=this.next,this.next=null;null!=(L=this.process());)(null==I||L!1},this.recall={},this.isParallel=!1,this.pFlow=null,this.shouldCache=!0}isStream(){return 0=this.iterators.length)return this.pos=0,null;if(!this.isDiscretized){for(var L=this.iterators[this.pos].next();L.done&&this.pos=this.iterators.length));)L=this.iterators[this.pos].next();return L.done?(this.pos=0,null):null===this.next?L.value:this.next.pipe(L.value)}var I=[];if(this.discreteStreamLength=Math.min(this.discreteStreamLength,this.iterators.length),1==this.discreteStreamLength){for(L=this.iterators[this.pos].next();L.done&&this.pos=this.iterators.length));)L=this.iterators[this.pos].next();if(L.done)return this.pos=0,null;for(;!L.done;){if(I.push(L.value),this.isDataEndObject.isDataEnd(L.value,I.length))return null===this.next?I:this.next.pipe(I);L=this.iterators[this.pos].next()}if(0O))break;var k=[];for(let O=0;Onull==O))break;if(this.streamElements.push(k),this.isDataEndObject.isDataEnd(k,this.streamElements.length)){this.recall.justEnded=!0;try{return null===this.next?this.streamElements.slice():this.next.pipe(this.streamElements.slice())}finally{this.streamElements=[]}}else this.recall.justEnded=!1}while(!0);return this.pos=0,delete this.recall.ended,delete this.recall.justEnded,this.streamElements=[],null}}merge(L){var I=this.isStream(),k=j.getIterator(L);if(!I&&k.streamer||I&&!k.streamer)throw new Error("Streamer cannot be merged with other data types");return this.iterators.push(k),this}startPush(){this.isListening||(this.isListening=!0,this.isStream()?this._listen():this._doPush())}stopPush(){if(this.isListening&&(this.isListening=!1,this.isStream()))for(let L of this.iterators)o(L.streamer,this)}_doPush(){var L;if(!this.isDiscretized)for(;this.isListening&&!(this.pos>=this.iterators.length);){for(L=this.iterators[this.pos].next();L.done&&this.pos=this.iterators.length));)L=this.iterators[this.pos].next();if(L.done)break;this.push(L.value)}else if(this.discreteStreamLength=Math.min(this.discreteStreamLength,this.iterators.length),1==this.discreteStreamLength)do{for(L=this.iterators[this.pos].next();!L.done;)this.streamElements.push(L.value),this.isDataEndObject.isDataEnd(L.value,this.streamElements.length)&&(this.push(this.streamElements.slice()),this.streamElements=[]),L=this.iterators[this.pos].next();if(0null==P))break;if(this.streamElements.push(O),!this.isDataEndObject.isDataEnd(O,this.streamElements.length))k=!1;else if(k=!0,this.push(this.streamElements.slice()),this.streamElements=[],m.from(I).allMatch(P=>P))break}while(!0)}this.isListening=!1,this.pos=0}_listen(){if(this.isDiscretized){var L=[];for(let I of this.iterators)I.streamer&&(L.push(I.streamer),s(I.streamer,this));this.recall.streamKeys=m.from(L).select(I=>I.key).collect(m.toArray),this.recall.queues=m.from(L).select(()=>new p).collect(m.toArray),this.discreteStreamLength=Math.min(L.length,this.discreteStreamLength),this.recall.ready=!0,this.recall.called=!1,this.streamElements=[]}else for(let I of this.iterators)I.streamer&&s(I.streamer,this)}_prePush(L,I){if(!this.isDiscretized)this.push(L);else{this.recall.queues[this.recall.streamKeys.indexOf(I.key)].enqueue(L);var k=this;if(!this.recall.ready)return;this.recall.ready=!1,setTimeout(function(){Outer:do{var O=[];for(let P=0;P=this.end)return;null===this.next?this.terminalFunc(L):this.next.push(L)}}}class g extends m{constructor(L){super(),this.pipeFunc=L}pipe(L){var I=this.pipeFunc(L);return I?(this._addElement(L),null===this.next?L:this.next.pipe(L)):this.prev.process()}push(L){var I=this.pipeFunc(L);I&&(null===this.next?this.terminalFunc(L):this.next.push(L))}}class F extends m{constructor(L){super(),this.pipeFunc=L,this.items=[],this.obtainedAll=!1,this.pos=0}process(){if(this.ended)return this._getElement();this.prev.next!=this&&(this.prev.next=this);var L;if(!this.obtainedAll){if(L=this.prev.process(),null!=L)return L;this.obtainedAll=!0,this.items.sort(this.pipeFunc)}if(this.posI.length)for(;this.span!=I.length;)I.push(null);if(this.items.push(I),!this.isDataEndObject.isDataEnd(I,this.items.length))return this.prev.process()}else if(this.items.push(I),!this.isDataEndObject.isDataEnd(I,this.items.length))return this.prev.process()}var M=this.spawnFlows?new v(this.items):this.items;try{return null===this.next?M:this.next.pipe(M)}finally{this.items=[]}}push(L){if(this.prev instanceof f&&!this.isDiscretized)this.items=L;else{var I=L;if(1!=this.span){if(!A.isArray(L)){var k=j.getFlow(L);I=[];var P,O=!1;for(let C=0;CI.length)for(;this.span!=I.length;)I.push(null);if(this.items.push(I),!this.isDataEndObject.isDataEnd(I,this.items.length))return}else if(this.items.push(L),!this.isDataEndObject.isDataEnd(L,this.items.length))return}var M;M=this.spawnFlows?new v(this.items):this.items,null===this.next?this.terminalFunc(M):this.next.push(M),this.items=[]}}class v extends f{constructor(L){super(j.createIteratorFromArray(L)),this.elements=L}elementSize(){return this.elements.length}streamSize(){try{return this.elements[0].length}catch(L){return 1}}}class _{constructor(L){this.listeners=[],this.receiver=L&&A.isFunction(L)?L:null,this.key=A.generateUUID()}push(L,I){null!=this.receiver&&this.receiver(L,I)}subscribe(L){if(L.notify&&A.isFunction(L.notify)||A.isFunction(L))this.listeners.push(L);else throw new Error("Listener object must either be a function or an object with a `notify` function.")}send(L){m.from(this.listeners).where(I=>I.notify&&A.isFunction(I.notify)).foreach(I=>I.notify(L)),m.from(this.listeners).where(I=>!(I.notify&&A.isFunction(I.notify))&&A.isFunction(I)).foreach(I=>I(L))}unsubscribe(L){let I=this.listeners.indexOf(L);0<=I&&this.listeners.splice(I,1)}size(){return 0}get(){return{}}}class j{static getFlow(L){return new f(j.getIterator(L))}static getIterator(L){let I;return I=A.isArray(L)&&!A.isString(L)?j.createIteratorFromArray(L):A.isMap(L)?j.createIteratorFromMap(L):A.isSet(L)?j.createIteratorFromSet(L):A.isString(L)&&L.toLowerCase().startsWith("fs://")?j.createIteratorFromFileSystem(L):A.isStreamer(L)?j.createIteratorFromStreamer(L):A.isGenerator(L)?j.createIteratorFromGenerator(L):A.isIterable(L)&&!A.isString(L)?j.createIteratorFromIterable(L):A.isObject(L)&&!A.isString(L)?j.createIteratorFromObject(L):j.createIteratorFromValue(L),I}static createIteratorFromArray(L){return function(I){let k=I,O=0;return{next:function(){try{return Ok.length&&(O=0)}}}}(L)}static createIteratorWithEmptyArraysFromNumber(L){L=Math.ceil(L);for(var I=[];L--;)I.push([]);return j.createIteratorFromArray(I)}static createIteratorFromMap(L){return function(I){let k=I,O=k.entries();return{next:function(){let P=O.next();return P.done?(O=k.entries(),P):{value:{key:P.value[0],value:P.value[1]},done:!1}}}}(L)}static createIteratorFromSet(L){return j.createIteratorFromArray(Array.from(L))}static createIteratorFromIterable(L){return L}static createIteratorFromGenerator(L){return function(I){let k=I,O=k(),P;return{next:function(){try{return P=O.next(),P}finally{P.done&&(O=k())}}}}(L)}static createIteratorFromObject(L){return function(I){let k=I,O=Object.keys(k),P=0,M=O.length;return{next:function(){try{return PM&&(P=0,O=Object.keys(k),M=O.length)}}}}(L)}static createIteratorFromFileSystem(L){return function(){"fs://"==L.trim().substring(0,"fs://".length)&&(L=L.trim().substring("fs://".length));let I=require("n-readlines"),k=new I(L);return{next:function(){let O=k.next();return O?{value:O.toString("utf8"),done:!1}:(k=new I(L),{done:!0})}}}()}static createIteratorFromValue(L){return function(){let I=!1;return{next:function(){try{return I?{done:!0}:{value:L,done:!1}}finally{I=!I}}}}()}static createIteratorFromStreamer(L){return function(){let I=L.size(),k={},O=0,P;return{next:function(){try{return O>=I?{done:!0}:(P=L.get(O),{value:null==P?k:P,done:!1})}finally{O++,O>I&&(O=0,I=L.size())}},streamer:L}}()}}var A={isFunction:function(L){return"function"==typeof L||!1},isArray:function(L){return"number"==typeof L.length&&0<=L.length},isSet:function(L){return L instanceof Set&&A.isFunction(L.values)},isMap:function(L){return L instanceof Map&&A.isFunction(L.values)},isObject:function(L){return!!L&&"object"==typeof L},isString:function(L){return"[object String]"===Object.prototype.toString.call(L)},isIn:function(L,I){for(let k=0;kO}start(){this.rootFlow.startPush()}stop(){this.rootFlow.stopPush()}push(L){this.streamer.push(L,this.key)}},t.Streamer=_,Object.defineProperty(t,"__esModule",{value:!0})}); \ No newline at end of file