iterable-linq-utility 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.cts +281 -0
- package/dist/index.d.ts +281 -0
- package/dist/iterable-linq-utility.js +256 -166
- package/dist/iterable-linq-utility.umd.cjs +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.IterableLinq={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.defineProperty,n=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r};function r(e){return typeof e==`function`}function i(e,t){return e<t?-1:e===t?0:1}function a(e){if(e==null)return i;if(r(e))return e;let t=Array.isArray(e)?e:[e];return(e,n)=>{for(let r of t){let t=i(e[r],n[r]);if(t!==0)return t}return 0}}function o(e,t,n){let r,i=!1;for(let a of e)!i||r==null&&a!=null?(r=a,i=!0):a!=null&&n*t(r,a)<0&&(r=a);return r}function s(e){return{done:!1,value:e}}function c(e){return{done:!0,value:e}}function l(e,t){return Error(`[iterable-linq-utility/${e}] ${t}`)}function u(e,t){if(e==null)throw l(t,`The "sourceIterable" must be provided`);if(!r(e[Symbol.iterator]))throw l(t,`The provided "sourceIterable" does not conform to the iterator protocol https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol. It must implement the "[Symbol.iterator]" function.`)}function d(e,t,n){if(!r(e))throw l(n,`The "${t}" function must be provided`)}function ee(e,t,n){if(!Number.isInteger(e))throw l(n,`The "${t}" parameter must be an integer`)}function f(e,t,n){if(!Number.isInteger(e)||e<0)throw l(n,`The "${t}" parameter must be a non-negative integer`)}function te(e,t,n){if(!Number.isFinite(e)||e===0)throw l(n,`The "${t}" parameter must be a finite number other than 0`)}function ne(e,t,n){if(typeof e!=`object`||!e)throw l(n,`The "${t}" parameter must be an object`)}function re(e,t,n){if(typeof e!=`string`||e.length===0)throw l(n,`The "${t}" parameter must be a non-empty string`)}function p(e,t){return u(e,`at`),ee(t,`index`,`at`),t>=0?ie(e,t):ae(e,-t)}function ie(e,t){let n=0;for(let r of e)if(n++===t)return r}function ae(e,t){let n=[],r=0,i=!1;for(let a of e)n[r]=a,++r===t&&(r=0,i=!0);return i?n[r]:void 0}function m(e){if(u(e,`collectToArray`),Array.isArray(e)||e instanceof Set)return Array.from(e);let t=[];for(let n of e)t.push(n);return t}function h(e,t){u(e,`count`);let n=0;if(t===void 0){for(let t of e)n++;return n}d(t,`predicate`,`count`);let r=0;for(let i of e)t(i,r++)&&n++;return n}var g=class{done=!1;next(){if(this.done)return c();let e=this.advance();return e.done===!0&&(this.done=!0),e}return(e){return this.done||(this.done=!0,this.onReturn(e)),c(e)}[Symbol.iterator](){return this}onReturn(e){}closeAfterCallbackError(){if(!this.done){this.done=!0;try{this.onReturn()}catch{}}}},_=class{createIterator;constructor(e){this.createIterator=e}[Symbol.iterator](){return this.createIterator()}},v=class extends g{source;index=0;constructor(e){super(),this.source=e[Symbol.iterator]()}onReturn(e){this.source.return?.(e)}};function oe(e,t){return new _(()=>new se(e,t))}var se=class extends g{state;step;constructor(e,t){super(),this.state=e,this.step=t}advance(){let e=this.step(this.state);return e===void 0?c():(this.state=e[1],s(e[0]))}};function y(e,t){return u(e,`distinct`),t!==void 0&&d(t,`keySelector`,`distinct`),new _(()=>new ce(e,t))}var ce=class extends v{keySelector;seen=new Set;constructor(e,t){super(e),this.keySelector=t}advance(){for(let e=this.source.next();;e=this.source.next()){if(e.done===!0)return e;let t=e.value;if(this.keySelector!==void 0)try{t=this.keySelector(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}if(!this.seen.has(t))return this.seen.add(t),e}}};function b(){return oe(void 0,()=>void 0)}function x(e,t){u(e,`every`),d(t,`predicate`,`every`);let n=0;for(let r of e)if(!t(r,n++))return!1;return!0}function S(e,t){return u(e,`filter`),d(t,`predicate`,`filter`),new _(()=>new le(e,t))}var le=class extends v{predicate;constructor(e,t){super(e),this.predicate=t}advance(){for(let e=this.source.next();;e=this.source.next()){if(e.done===!0)return e;let t;try{t=this.predicate(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}if(t)return e}}};function C(e,t){u(e,`find`),d(t,`predicate`,`find`);let n=0;for(let r of e)if(t(r,n++))return r}function w(e,t){u(e,`findIndex`),d(t,`predicate`,`findIndex`);let n=0;for(let r of e){if(t(r,n))return n;n++}return-1}function T(e,t){u(e,`findLast`),d(t,`predicate`,`findLast`);let n,r=0;for(let i of e)t(i,r++)&&(n=i);return n}function E(e,t){u(e,`findLastIndex`),d(t,`predicate`,`findLastIndex`);let n=-1,r=0;for(let i of e)t(i,r)&&(n=r),r++;return n}function D(e,t){return u(e,`flatMap`),d(t,`mapper`,`flatMap`),new _(()=>new ue(e,t))}var ue=class e extends v{mapper;static steps={outer:t=>{let n=t.source.next();if(n.done===!0)return n;let r=e.mapNext(t,n.value);if(r===void 0){t.state=`inner`;return}if(r.length!==0)return t.array=r,t.position=1,t.state=`array`,s(r[0])},inner:t=>{let n=e.nextInner(t);if(n.done!==!0)return n;t.inner=void 0,t.state=`outer`},array:e=>{if(e.position<e.array.length)return s(e.array[e.position++]);e.array=void 0,e.state=`outer`}};state=`outer`;inner;array;position=0;constructor(e,t){super(e),this.mapper=t}advance(){for(;;){let t=e.steps[this.state](this);if(t!==void 0)return t}}onReturn(e){this.array=void 0;try{this.inner?.return?.(e)}finally{super.onReturn(e)}}static mapNext(e,t){try{let n=e.mapper(t,e.index++);if(Array.isArray(n))return n;e.inner=n[Symbol.iterator]();return}catch(t){throw e.closeAfterCallbackError(),t}}static nextInner(e){try{return e.inner.next()}catch(t){throw e.inner=void 0,e.closeAfterCallbackError(),t}}},O=class e{static instance=e.createFrozen();constructor(){}static createFrozen(){let t=new e;return Object.freeze(t),t}};function k(){return O.instance}function A(e,t){u(e,`forEach`),d(t,`action`,`forEach`);let n=0;for(let r of e)t(r,n++);return k()}async function j(e,t){u(e,`forEachAsync`),d(t,`action`,`forEachAsync`);let n=0;for(let r of e)await t(r,n++);return k()}function M(e,t){u(e,`includes`);let n=t!==t;for(let r of e)if(r===t||n&&r!==r)return!0;return!1}function N(e,t){u(e,`indexOf`);let n=0;for(let r of e){if(r===t)return n;n++}return-1}function P(e,t){u(e,`lastIndexOf`);let n=-1,r=0;for(let i of e)i===t&&(n=r),r++;return n}function F(e,t){return u(e,`map`),d(t,`mapper`,`map`),new _(()=>new de(e,t))}var de=class extends v{mapper;constructor(e,t){super(e),this.mapper=t}advance(){let e=this.source.next();if(e.done===!0)return e;let t;try{t=this.mapper(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}return s(t)}};function fe(e){u(e,`LinkedList.from`);let t=new pe;for(let n of e)t.addLast(n);return t}var pe=class{internalSize=0;head=null;tail=null;[Symbol.iterator](){return new me(this.head)}addFirst(e){let t={data:e,nextNode:this.head};return this.tail===null&&(this.tail=t),this.head=t,this.internalSize++,this}addLast(e){let t={data:e,nextNode:null};return this.tail===null?this.head=t:this.tail.nextNode=t,this.tail=t,this.internalSize++,this}size(){return this.internalSize}},me=class extends g{current;constructor(e){super(),this.current=e}advance(){let e=this.current;return e===null?c():(this.current=e.nextNode,s(e.data))}};function he(e){return u(e,`materialize`),e instanceof I?e:new I(e)}var I=class{source;constructor(e){this.source=fe(e)}[Symbol.iterator](){return this.source[Symbol.iterator]()}};function L(e,t){return u(e,`max`),o(e,a(t),1)}function R(){return{allowPartialMemoization:!0}}function z(e,t){u(e,`memoize`);let n={...R(),...t}.allowPartialMemoization;return e instanceof H?n?e.changePartialMemoizationBehaviour():e:e instanceof U?n?e:e.changePartialMemoizationBehaviour():n?new U(e):new H(e)}function B(){return{values:[],finished:!1}}function V(e,t){if(t.error)throw t.error.value;if(t.finished)return!1;t.source??=e[Symbol.iterator]();let n;try{n=t.source.next()}catch(e){throw t.error={value:e},t.source=void 0,e}return n.done===!0?(t.finished=!0,t.source=void 0,!1):(t.values.push(n.value),!0)}var H=class{source;cache=B();constructor(e){this.source=e}[Symbol.iterator](){return new W(this.source,this.cache,!0)}changePartialMemoizationBehaviour(){return new U(this.source)}},U=class{source;cache=B();constructor(e){this.source=e}[Symbol.iterator](){return new W(this.source,this.cache,!1)}changePartialMemoizationBehaviour(){return new H(this.source)}},W=class extends g{source;cache;drainFirst;index=0;constructor(e,t,n){super(),this.source=e,this.cache=t,this.drainFirst=n}advance(){if(this.drainFirst)for(;V(this.source,this.cache););return this.index<this.cache.values.length||V(this.source,this.cache)?s(this.cache.values[this.index++]):c()}};function G(e,t){return u(e,`min`),o(e,a(t),-1)}function K(e,t,n){let r=typeof t==`number`,i=r?e:0,a=r?t:e;if(!r&&n!==void 0)throw l(`range`,`The "options" parameter must be the second argument when "start" is omitted`);let o=r?n:t;o!==void 0&&ne(o,`options`,`range`);let{step:s=1,reverse:c=!1}=o??{};te(s,`step`,`range`);let u=ge(i,a,Math.abs(s),c);return u.length>0?new _(()=>new _e(u.first,u.step,u.length)):b()}function ge(e,t,n,r){let i=t<e?-n:n,a=Math.ceil(Math.abs(t-e)/n);return r?{first:e+(a-1)*i,step:-i,length:a}:{first:e,step:i,length:a}}var _e=class extends g{first;step;length;index=0;constructor(e,t,n){super(),this.first=e,this.step=t,this.length=n}advance(){return this.index>=this.length?c():s(this.first+this.index++*this.step)}};function q(e,...t){if(u(e,`reduce`),t.length===1)return ve(e,t[0]);let[n,r]=t;d(r,`reducer`,`reduce`);let i=n,a=0;for(let t of e)i=r(i,t,a++);return i}function ve(e,t){d(t,`reducer`,`reduce`);let n,r=0;for(let i of e)n=r===0?i:t(n,i,r),r++;if(r===0)throw l(`reduce`,`The "sourceIterable" must not be empty when "reduce" has no seed`);return n}function J(e,t){return f(t,`count`,`repeat`),oe(t,t=>t>0?[e,t-1]:void 0)}function ye(e,t){return u(e,`skip`),f(t,`count`,`skip`),new _(()=>new be(e,t))}var be=class extends v{count;constructor(e,t){super(e),this.count=t}advance(){for(;this.index<this.count;){let e=this.source.next();if(e.done===!0)return e;this.index++}return this.source.next()}};function xe(e,t){return u(e,`skipWhile`),d(t,`predicate`,`skipWhile`),new _(()=>new Se(e,t))}var Se=class extends v{predicate;skipping=!0;constructor(e,t){super(e),this.predicate=t}advance(){if(!this.skipping)return this.source.next();for(let e=this.source.next();;e=this.source.next()){if(e.done===!0)return e;let t;try{t=this.predicate(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}if(!t)return this.skipping=!1,e}}};function Ce(e,t){if(u(e,`some`),t===void 0){for(let t of e)return!0;return!1}d(t,`predicate`,`some`);let n=0;for(let r of e)if(t(r,n++))return!0;return!1}function we(e,t){return u(e,`take`),f(t,`count`,`take`),new _(()=>new Te(e,t))}var Te=class extends v{count;constructor(e,t){super(e),this.count=t}advance(){if(this.index>=this.count)return this.source.return?.(),c();let e=this.source.next();return e.done===!0?e:(this.index++,s(e.value))}};function Ee(e,t){return u(e,`takeWhile`),d(t,`predicate`,`takeWhile`),new _(()=>new De(e,t))}var De=class extends v{predicate;constructor(e,t){super(e),this.predicate=t}advance(){let e=this.source.next();if(e.done===!0)return e;let t;try{t=this.predicate(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}return t?e:(this.source.return?.(),c())}};function Oe(e,t){return u(e,`tap`),d(t,`tapper`,`tap`),new _(()=>new ke(e,t))}var ke=class extends v{tapper;constructor(e,t){super(e),this.tapper=t}advance(){let e=this.source.next();if(e.done===!0)return e;try{this.tapper(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}return e}};function Ae(e,t){return u(e,`tapChain`),d(t,`tapper`,`tapChain`),new _(()=>(t(e,0),e[Symbol.iterator]()))}var je=n({at:()=>p,collectToArray:()=>m,count:()=>h,distinct:()=>y,empty:()=>b,every:()=>x,filter:()=>S,find:()=>C,findIndex:()=>w,findLast:()=>T,findLastIndex:()=>E,flatMap:()=>D,forEach:()=>A,forEachAsync:()=>j,getMemoizeDefaultOptions:()=>R,includes:()=>M,indexOf:()=>N,lastIndexOf:()=>P,map:()=>F,materialize:()=>he,max:()=>L,memoize:()=>z,min:()=>G,range:()=>K,reduce:()=>q,repeat:()=>J,skip:()=>ye,skipWhile:()=>xe,some:()=>Ce,take:()=>we,takeWhile:()=>Ee,tap:()=>Oe,tapChain:()=>Ae}),Y=Symbol.for(`iterable-linq-utility.IIterableLinq`);function X(e){return new Z(e)}var Z=class{iterable;constructor(e){this.iterable=e}[Symbol.iterator](){return this.iterable[Symbol.iterator]()}at(e){return p(this.iterable,e)}collectToArray(){return m(this.iterable)}count(e){return h(this.iterable,e)}distinct(e){return X(y(this.iterable,e))}every(e){return x(this.iterable,e)}filter(e){return X(S(this.iterable,e))}find(e){return C(this.iterable,e)}findIndex(e){return w(this.iterable,e)}findLast(e){return T(this.iterable,e)}findLastIndex(e){return E(this.iterable,e)}flatMap(e){return X(D(this.iterable,e))}forEach(e){return A(this.iterable,e)}forEachAsync(e){return j(this.iterable,e)}includes(e){return M(this.iterable,e)}indexOf(e){return N(this.iterable,e)}lastIndexOf(e){return P(this.iterable,e)}map(e){return X(F(this.iterable,e))}materialize(){return X(he(this.iterable))}max(e){return L(this.iterable,e)}memoize(e){return X(z(this.iterable,e))}min(e){return G(this.iterable,e)}reduce(...e){return e.length===1?q(this.iterable,e[0]):q(this.iterable,e[0],e[1])}skip(e){return X(ye(this.iterable,e))}skipWhile(e){return X(xe(this.iterable,e))}some(e){return Ce(this.iterable,e)}take(e){return X(we(this.iterable,e))}takeWhile(e){return X(Ee(this.iterable,e))}tap(e){return X(Oe(this.iterable,e))}tapChain(e){return X(Ae(this.iterable,e))}tapChainCreation(e){d(e,`chainCreationTapper`,`tapChainCreation`);let t=this;return e(t),t}};Object.defineProperty(Z.prototype,Y,{value:!0,enumerable:!1,writable:!1,configurable:!1});function Q(){return Z.prototype}function Me(e){return typeof e==`object`&&!!e&&e[Y]===!0}function Ne(e,t){let n=Object.getOwnPropertyDescriptor(Q(),e);Object.defineProperty(Q(),e,{value:t,enumerable:!1,writable:n?.writable??!1,configurable:!0})}function Pe(e,t,n){re(t,`name`,e),d(n,`implementation`,e)}function Fe(e,t){if(Pe(`extend`,e,t),e in X([]))throw l(`extend`,`"${e}" already exists on IIterableLinq: use override() to replace it`);Ne(e,t)}function Ie(e,t){Pe(`override`,e,t);let n=e;if(!(n!==`constructor`&&Object.prototype.hasOwnProperty.call(Q(),n)))throw l(`override`,`"${n}" is not a method of IIterableLinq: use extend() to add it`);Ne(n,t)}function Le(){return $(b())}function $(e){return u(e,`from`),X(e)}function Re(e,t,n){if(typeof t==`number`)return $(K(e,t,n));if(n!==void 0)throw l(`fromRange`,`The "options" parameter must be the second argument when "start" is omitted`);return $(K(e,t))}function ze(e,t){return $(J(e,t))}Object.defineProperty(e,"Functions",{enumerable:!0,get:function(){return je}}),e.Unit=O,e.empty=Le,e.extend=Fe,e.from=$,e.fromRange=Re,e.isIterableLinq=Me,e.override=Ie,e.repeat=ze,e.unit=k});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.IterableLinq={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.defineProperty,n=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r};function r(e){return typeof e==`function`}function i(e,t){return e<t?-1:e===t?0:1}function a(e){if(e==null)return i;if(r(e))return e;let t=Array.isArray(e)?e:[e];return(e,n)=>{for(let r of t){let t=i(e[r],n[r]);if(t!==0)return t}return 0}}function o(e,t,n){let r,i=!1;for(let a of e)!i||r==null&&a!=null?(r=a,i=!0):a!=null&&n*t(r,a)<0&&(r=a);return r}function s(e){return{done:!1,value:e}}function c(e){return{done:!0,value:e}}function l(e,t){return Error(`[iterable-linq-utility/${e}] ${t}`)}function u(e,t){if(e==null)throw l(t,`The "sourceIterable" must be provided`);if(!r(e[Symbol.iterator]))throw l(t,`The provided "sourceIterable" does not conform to the iterator protocol https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol. It must implement the "[Symbol.iterator]" function.`)}function d(e,t,n){if(!r(e))throw l(n,`The "${t}" function must be provided`)}function ee(e,t,n){if(!Number.isInteger(e))throw l(n,`The "${t}" parameter must be an integer`)}function f(e,t,n){if(!Number.isInteger(e)||e<0)throw l(n,`The "${t}" parameter must be a non-negative integer`)}function te(e,t,n){if(!Number.isFinite(e)||e===0)throw l(n,`The "${t}" parameter must be a finite number other than 0`)}function ne(e,t,n){if(typeof e!=`object`||!e)throw l(n,`The "${t}" parameter must be an object`)}function re(e,t,n){if(typeof e!=`string`||e.length===0)throw l(n,`The "${t}" parameter must be a non-empty string`)}function p(e,t){return u(e,`at`),ee(t,`index`,`at`),t>=0?ie(e,t):ae(e,-t)}function ie(e,t){let n=0;for(let r of e)if(n++===t)return r}function ae(e,t){let n=[],r=0,i=!1;for(let a of e)n[r]=a,++r===t&&(r=0,i=!0);return i?n[r]:void 0}function m(e,t){u(e,`average`);let n=0,r=0;if(t===void 0)for(let t of e)n+=t,r++;else{d(t,`selector`,`average`);for(let i of e)n+=t(i,r++)}return r===0?void 0:n/r}function h(e){if(u(e,`collectToArray`),Array.isArray(e)||e instanceof Set)return Array.from(e);let t=[];for(let n of e)t.push(n);return t}function g(e,t){u(e,`count`);let n=0;if(t===void 0){for(let t of e)n++;return n}d(t,`predicate`,`count`);let r=0;for(let i of e)t(i,r++)&&n++;return n}var _=class{done=!1;next(){if(this.done)return c();let e=this.advance();return e.done===!0&&(this.done=!0),e}return(e){return this.done||(this.done=!0,this.onReturn(e)),c(e)}[Symbol.iterator](){return this}onReturn(e){}closeAfterCallbackError(){if(!this.done){this.done=!0;try{this.onReturn()}catch{}}}},v=class{createIterator;constructor(e){this.createIterator=e}[Symbol.iterator](){return this.createIterator()}},y=class extends _{source;index=0;constructor(e){super(),this.source=e[Symbol.iterator]()}onReturn(e){this.source.return?.(e)}};function oe(e,t){return new v(()=>new se(e,t))}var se=class extends _{state;step;constructor(e,t){super(),this.state=e,this.step=t}advance(){let e=this.step(this.state);return e===void 0?c():(this.state=e[1],s(e[0]))}};function b(e,t){return u(e,`distinct`),t!==void 0&&d(t,`keySelector`,`distinct`),new v(()=>new ce(e,t))}var ce=class extends y{keySelector;seen=new Set;constructor(e,t){super(e),this.keySelector=t}advance(){for(let e=this.source.next();;e=this.source.next()){if(e.done===!0)return e;let t=e.value;if(this.keySelector!==void 0)try{t=this.keySelector(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}if(!this.seen.has(t))return this.seen.add(t),e}}};function x(){return oe(void 0,()=>void 0)}function le(e,t){u(e,`every`),d(t,`predicate`,`every`);let n=0;for(let r of e)if(!t(r,n++))return!1;return!0}function S(e,t){return u(e,`filter`),d(t,`predicate`,`filter`),new v(()=>new ue(e,t))}var ue=class extends y{predicate;constructor(e,t){super(e),this.predicate=t}advance(){for(let e=this.source.next();;e=this.source.next()){if(e.done===!0)return e;let t;try{t=this.predicate(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}if(t)return e}}};function C(e,t){u(e,`find`),d(t,`predicate`,`find`);let n=0;for(let r of e)if(t(r,n++))return r}function w(e,t){u(e,`findIndex`),d(t,`predicate`,`findIndex`);let n=0;for(let r of e){if(t(r,n))return n;n++}return-1}function T(e,t){u(e,`findLast`),d(t,`predicate`,`findLast`);let n,r=0;for(let i of e)t(i,r++)&&(n=i);return n}function E(e,t){u(e,`findLastIndex`),d(t,`predicate`,`findLastIndex`);let n=-1,r=0;for(let i of e)t(i,r)&&(n=r),r++;return n}function D(e,t){return u(e,`flatMap`),d(t,`mapper`,`flatMap`),new v(()=>new de(e,t))}var de=class e extends y{mapper;static steps={outer:t=>{let n=t.source.next();if(n.done===!0)return n;let r=e.mapNext(t,n.value);if(r===void 0){t.state=`inner`;return}if(r.length!==0)return t.array=r,t.position=1,t.state=`array`,s(r[0])},inner:t=>{let n=e.nextInner(t);if(n.done!==!0)return n;t.inner=void 0,t.state=`outer`},array:e=>{if(e.position<e.array.length)return s(e.array[e.position++]);e.array=void 0,e.state=`outer`}};state=`outer`;inner;array;position=0;constructor(e,t){super(e),this.mapper=t}advance(){for(;;){let t=e.steps[this.state](this);if(t!==void 0)return t}}onReturn(e){this.array=void 0;try{this.inner?.return?.(e)}finally{super.onReturn(e)}}static mapNext(e,t){try{let n=e.mapper(t,e.index++);if(Array.isArray(n))return n;e.inner=n[Symbol.iterator]();return}catch(t){throw e.closeAfterCallbackError(),t}}static nextInner(e){try{return e.inner.next()}catch(t){throw e.inner=void 0,e.closeAfterCallbackError(),t}}},O=class e{static instance=e.createFrozen();constructor(){}static createFrozen(){let t=new e;return Object.freeze(t),t}};function k(){return O.instance}function A(e,t){u(e,`forEach`),d(t,`action`,`forEach`);let n=0;for(let r of e)t(r,n++);return k()}async function j(e,t){u(e,`forEachAsync`),d(t,`action`,`forEachAsync`);let n=0;for(let r of e)await t(r,n++);return k()}function M(e,t){u(e,`includes`);let n=t!==t;for(let r of e)if(r===t||n&&r!==r)return!0;return!1}function N(e,t){u(e,`indexOf`);let n=0;for(let r of e){if(r===t)return n;n++}return-1}function P(e,t){return u(e,`join`),Array.from(e).join(t)}function F(e,t){u(e,`lastIndexOf`);let n=-1,r=0;for(let i of e)i===t&&(n=r),r++;return n}function I(e,t){return u(e,`map`),d(t,`mapper`,`map`),new v(()=>new fe(e,t))}var fe=class extends y{mapper;constructor(e,t){super(e),this.mapper=t}advance(){let e=this.source.next();if(e.done===!0)return e;let t;try{t=this.mapper(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}return s(t)}};function pe(e){u(e,`LinkedList.from`);let t=new me;for(let n of e)t.addLast(n);return t}var me=class{internalSize=0;head=null;tail=null;[Symbol.iterator](){return new he(this.head)}addFirst(e){let t={data:e,nextNode:this.head};return this.tail===null&&(this.tail=t),this.head=t,this.internalSize++,this}addLast(e){let t={data:e,nextNode:null};return this.tail===null?this.head=t:this.tail.nextNode=t,this.tail=t,this.internalSize++,this}size(){return this.internalSize}},he=class extends _{current;constructor(e){super(),this.current=e}advance(){let e=this.current;return e===null?c():(this.current=e.nextNode,s(e.data))}};function L(e){return u(e,`materialize`),e instanceof R?e:new R(e)}var R=class{source;constructor(e){this.source=pe(e)}[Symbol.iterator](){return this.source[Symbol.iterator]()}};function z(e,t){return u(e,`max`),o(e,a(t),1)}function B(){return{allowPartialMemoization:!0}}function V(e,t){u(e,`memoize`);let n={...B(),...t}.allowPartialMemoization;return e instanceof W?n?e.changePartialMemoizationBehaviour():e:e instanceof G?n?e:e.changePartialMemoizationBehaviour():n?new G(e):new W(e)}function H(){return{values:[],finished:!1}}function U(e,t){if(t.error)throw t.error.value;if(t.finished)return!1;t.source??=e[Symbol.iterator]();let n;try{n=t.source.next()}catch(e){throw t.error={value:e},t.source=void 0,e}return n.done===!0?(t.finished=!0,t.source=void 0,!1):(t.values.push(n.value),!0)}var W=class{source;cache=H();constructor(e){this.source=e}[Symbol.iterator](){return new K(this.source,this.cache,!0)}changePartialMemoizationBehaviour(){return new G(this.source)}},G=class{source;cache=H();constructor(e){this.source=e}[Symbol.iterator](){return new K(this.source,this.cache,!1)}changePartialMemoizationBehaviour(){return new W(this.source)}},K=class extends _{source;cache;drainFirst;index=0;constructor(e,t,n){super(),this.source=e,this.cache=t,this.drainFirst=n}advance(){if(this.drainFirst)for(;U(this.source,this.cache););return this.index<this.cache.values.length||U(this.source,this.cache)?s(this.cache.values[this.index++]):c()}};function q(e,t){return u(e,`min`),o(e,a(t),-1)}function J(e,t,n){let r=typeof t==`number`,i=r?e:0,a=r?t:e;if(!r&&n!==void 0)throw l(`range`,`The "options" parameter must be the second argument when "start" is omitted`);let o=r?n:t;o!==void 0&&ne(o,`options`,`range`);let{step:s=1,reverse:c=!1}=o??{};te(s,`step`,`range`);let u=ge(i,a,Math.abs(s),c);return u.length>0?new v(()=>new _e(u.first,u.step,u.length)):x()}function ge(e,t,n,r){let i=t<e?-n:n,a=Math.ceil(Math.abs(t-e)/n);return r?{first:e+(a-1)*i,step:-i,length:a}:{first:e,step:i,length:a}}var _e=class extends _{first;step;length;index=0;constructor(e,t,n){super(),this.first=e,this.step=t,this.length=n}advance(){return this.index>=this.length?c():s(this.first+this.index++*this.step)}};function Y(e,...t){if(u(e,`reduce`),t.length===1)return ve(e,t[0]);let[n,r]=t;d(r,`reducer`,`reduce`);let i=n,a=0;for(let t of e)i=r(i,t,a++);return i}function ve(e,t){d(t,`reducer`,`reduce`);let n,r=0;for(let i of e)n=r===0?i:t(n,i,r),r++;if(r===0)throw l(`reduce`,`The "sourceIterable" must not be empty when "reduce" has no seed`);return n}function ye(e,t){return f(t,`count`,`repeat`),oe(t,t=>t>0?[e,t-1]:void 0)}function be(e,t){return e===t}function xe(e,t,n){u(e,`sequenceEqual`),u(t,`sequenceEqual`),n!==void 0&&d(n,`equals`,`sequenceEqual`);let r=n??be,i=t[Symbol.iterator](),a=!0;try{for(let t of e){a=!1;let e=i.next();if(e.done===!0||(a=!0,!r(t,e.value)))return!1}return a=!1,i.next().done===!0||(a=!0,!1)}finally{a&&i.return?.()}}function Se(e,t){u(e,`single`);let n=!1,r;if(t===void 0){for(let t of e){if(n)throw l(`single`,`The iterable contains more than one value`);n=!0,r=t}return r}d(t,`predicate`,`single`);let i=0;for(let a of e)if(t(a,i++)){if(n)throw l(`single`,`More than one value satisfies the predicate`);n=!0,r=a}return r}function Ce(e,t){return u(e,`skip`),f(t,`count`,`skip`),new v(()=>new we(e,t))}var we=class extends y{count;constructor(e,t){super(e),this.count=t}advance(){for(;this.index<this.count;){let e=this.source.next();if(e.done===!0)return e;this.index++}return this.source.next()}};function Te(e,t){return u(e,`skipWhile`),d(t,`predicate`,`skipWhile`),new v(()=>new Ee(e,t))}var Ee=class extends y{predicate;skipping=!0;constructor(e,t){super(e),this.predicate=t}advance(){if(!this.skipping)return this.source.next();for(let e=this.source.next();;e=this.source.next()){if(e.done===!0)return e;let t;try{t=this.predicate(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}if(!t)return this.skipping=!1,e}}};function De(e,t){if(u(e,`some`),t===void 0){for(let t of e)return!0;return!1}d(t,`predicate`,`some`);let n=0;for(let r of e)if(t(r,n++))return!0;return!1}function Oe(e,t){u(e,`sum`);let n=0;if(t===void 0){for(let t of e)n+=t;return n}d(t,`selector`,`sum`);let r=0;for(let i of e)n+=t(i,r++);return n}function ke(e,t){return u(e,`take`),f(t,`count`,`take`),new v(()=>new Ae(e,t))}var Ae=class extends y{count;constructor(e,t){super(e),this.count=t}advance(){if(this.index>=this.count)return this.source.return?.(),c();let e=this.source.next();return e.done===!0?e:(this.index++,s(e.value))}};function je(e,t){return u(e,`takeWhile`),d(t,`predicate`,`takeWhile`),new v(()=>new Me(e,t))}var Me=class extends y{predicate;constructor(e,t){super(e),this.predicate=t}advance(){let e=this.source.next();if(e.done===!0)return e;let t;try{t=this.predicate(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}return t?e:(this.source.return?.(),c())}};function Ne(e,t){return u(e,`tap`),d(t,`tapper`,`tap`),new v(()=>new Pe(e,t))}var Pe=class extends y{tapper;constructor(e,t){super(e),this.tapper=t}advance(){let e=this.source.next();if(e.done===!0)return e;try{this.tapper(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}return e}};function Fe(e,t){return u(e,`tapChain`),d(t,`tapper`,`tapChain`),new v(()=>(t(e,0),e[Symbol.iterator]()))}var Ie=n({at:()=>p,average:()=>m,collectToArray:()=>h,count:()=>g,distinct:()=>b,empty:()=>x,every:()=>le,filter:()=>S,find:()=>C,findIndex:()=>w,findLast:()=>T,findLastIndex:()=>E,flatMap:()=>D,forEach:()=>A,forEachAsync:()=>j,getMemoizeDefaultOptions:()=>B,includes:()=>M,indexOf:()=>N,join:()=>P,lastIndexOf:()=>F,map:()=>I,materialize:()=>L,max:()=>z,memoize:()=>V,min:()=>q,range:()=>J,reduce:()=>Y,repeat:()=>ye,sequenceEqual:()=>xe,single:()=>Se,skip:()=>Ce,skipWhile:()=>Te,some:()=>De,sum:()=>Oe,take:()=>ke,takeWhile:()=>je,tap:()=>Ne,tapChain:()=>Fe}),Le=Symbol.for(`iterable-linq-utility.IIterableLinq`);function X(e){return new Z(e)}var Z=class{iterable;constructor(e){this.iterable=e}[Symbol.iterator](){return this.iterable[Symbol.iterator]()}at(e){return p(this.iterable,e)}average(e){return m(this.iterable,e)}collectToArray(){return h(this.iterable)}count(e){return g(this.iterable,e)}distinct(e){return X(b(this.iterable,e))}every(e){return le(this.iterable,e)}filter(e){return X(S(this.iterable,e))}find(e){return C(this.iterable,e)}findIndex(e){return w(this.iterable,e)}findLast(e){return T(this.iterable,e)}findLastIndex(e){return E(this.iterable,e)}flatMap(e){return X(D(this.iterable,e))}forEach(e){return A(this.iterable,e)}forEachAsync(e){return j(this.iterable,e)}includes(e){return M(this.iterable,e)}indexOf(e){return N(this.iterable,e)}join(e){return P(this.iterable,e)}lastIndexOf(e){return F(this.iterable,e)}map(e){return X(I(this.iterable,e))}materialize(){return X(L(this.iterable))}max(e){return z(this.iterable,e)}memoize(e){return X(V(this.iterable,e))}min(e){return q(this.iterable,e)}reduce(...e){return e.length===1?Y(this.iterable,e[0]):Y(this.iterable,e[0],e[1])}sequenceEqual(e,t){return xe(this.iterable,e,t)}single(e){return Se(this.iterable,e)}skip(e){return X(Ce(this.iterable,e))}skipWhile(e){return X(Te(this.iterable,e))}some(e){return De(this.iterable,e)}sum(e){return Oe(this.iterable,e)}take(e){return X(ke(this.iterable,e))}takeWhile(e){return X(je(this.iterable,e))}tap(e){return X(Ne(this.iterable,e))}tapChain(e){return X(Fe(this.iterable,e))}tapChainCreation(e){d(e,`chainCreationTapper`,`tapChainCreation`);let t=this;return e(t),t}};Object.defineProperty(Z.prototype,Le,{value:!0,enumerable:!1,writable:!1,configurable:!1});function Q(){return Z.prototype}function Re(e){return typeof e==`object`&&!!e&&e[Le]===!0}function ze(e,t){let n=Object.getOwnPropertyDescriptor(Q(),e);Object.defineProperty(Q(),e,{value:t,enumerable:!1,writable:n?.writable??!1,configurable:!0})}function Be(e,t,n){re(t,`name`,e),d(n,`implementation`,e)}function Ve(e,t){if(Be(`extend`,e,t),e in X([]))throw l(`extend`,`"${e}" already exists on IIterableLinq: use override() to replace it`);ze(e,t)}function He(e,t){Be(`override`,e,t);let n=e;if(!(n!==`constructor`&&Object.prototype.hasOwnProperty.call(Q(),n)))throw l(`override`,`"${n}" is not a method of IIterableLinq: use extend() to add it`);ze(n,t)}function Ue(){return $(x())}function $(e){return u(e,`from`),X(e)}function We(e,t,n){if(typeof t==`number`)return $(J(e,t,n));if(n!==void 0)throw l(`fromRange`,`The "options" parameter must be the second argument when "start" is omitted`);return $(J(e,t))}function Ge(e,t){return $(ye(e,t))}Object.defineProperty(e,"Functions",{enumerable:!0,get:function(){return Ie}}),e.Unit=O,e.empty=Ue,e.extend=Ve,e.from=$,e.fromRange=We,e.isIterableLinq=Re,e.override=He,e.repeat=Ge,e.unit=k});
|
package/package.json
CHANGED