iterable-linq-utility 0.5.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.
@@ -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){if(e==null)throw Error(`The "sourceIterable" must be provided`);if(!r(e[Symbol.iterator]))throw Error(`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 u(e,t){if(!r(e))throw Error(`The "${t}" function must be provided`)}function d(e,t){if(!Number.isInteger(e)||e<0)throw Error(`The "${t}" parameter must be a non-negative integer`)}function ee(e,t){if(!Number.isFinite(e)||e===0)throw Error(`The "${t}" parameter must be a finite number other than 0`)}function te(e,t){if(typeof e!=`object`||!e)throw Error(`The "${t}" parameter must be an object`)}function ne(e,t){if(typeof e!=`string`||e.length===0)throw Error(`The "${t}" parameter must be a non-empty string`)}function re(e){if(l(e),Array.isArray(e)||e instanceof Set)return Array.from(e);let t=[];for(let n of e)t.push(n);return t}function f(e,t){l(e);let n=0;if(t===void 0){for(let t of e)n++;return n}u(t,`predicate`);let r=0;for(let i of e)t(i,r++)&&n++;return n}var p=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{}}}},m=class{createIterator;constructor(e){this.createIterator=e}[Symbol.iterator](){return this.createIterator()}},h=class extends p{source;index=0;constructor(e){super(),this.source=e[Symbol.iterator]()}onReturn(e){this.source.return?.(e)}};function g(e,t){return new m(()=>new ie(e,t))}var ie=class extends p{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 ae(e,t){return l(e),t!==void 0&&u(t,`keySelector`),new m(()=>new oe(e,t))}var oe=class extends h{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 _(){return g(void 0,()=>void 0)}function v(e,t){l(e),u(t,`predicate`);let n=0;for(let r of e)if(!t(r,n++))return!1;return!0}function se(e,t){return l(e),u(t,`predicate`),new m(()=>new ce(e,t))}var ce=class extends h{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 y(e,t){l(e),u(t,`predicate`);let n=0;for(let r of e)if(t(r,n++))return r}function b(e,t){l(e),u(t,`predicate`);let n=0;for(let r of e){if(t(r,n))return n;n++}return-1}function x(e,t){return l(e),u(t,`mapper`),new m(()=>new le(e,t))}var le=class e extends h{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}}},S=class e{static instance=e.createFrozen();constructor(){}static createFrozen(){let t=new e;return Object.freeze(t),t}};function C(){return S.instance}function w(e,t){l(e),u(t,`action`);let n=0;for(let r of e)t(r,n++);return C()}async function T(e,t){l(e),u(t,`action`);let n=0;for(let r of e)await t(r,n++);return C()}function E(e,t){l(e);let n=t!==t;for(let r of e)if(r===t||n&&r!==r)return!0;return!1}function D(e,t){return l(e),u(t,`mapper`),new m(()=>new ue(e,t))}var ue=class extends h{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 de(e){l(e);let t=new fe;for(let n of e)t.addLast(n);return t}var fe=class{internalSize=0;head=null;tail=null;[Symbol.iterator](){return new pe(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}},pe=class extends p{current;constructor(e){super(),this.current=e}advance(){let e=this.current;return e===null?c():(this.current=e.nextNode,s(e.data))}};function O(e){return l(e),e instanceof k?e:new k(e)}var k=class{source;constructor(e){this.source=de(e)}[Symbol.iterator](){return this.source[Symbol.iterator]()}};function A(e,t){return l(e),o(e,a(t),1)}function j(){return{allowPartialMemoization:!0}}function M(e,t){l(e);let n={...j(),...t}.allowPartialMemoization;return e instanceof P?n?e.changePartialMemoizationBehaviour():e:e instanceof F?n?e:e.changePartialMemoizationBehaviour():n?new F(e):new P(e)}function N(){return{values:[],finished:!1}}function me(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 P=class{source;cache=N();constructor(e){this.source=e}[Symbol.iterator](){return new I(this.source,this.cache,!0)}changePartialMemoizationBehaviour(){return new F(this.source)}},F=class{source;cache=N();constructor(e){this.source=e}[Symbol.iterator](){return new I(this.source,this.cache,!1)}changePartialMemoizationBehaviour(){return new P(this.source)}},I=class extends p{source;cache;drainFirst;index=0;constructor(e,t,n){super(),this.source=e,this.cache=t,this.drainFirst=n}advance(){if(this.drainFirst)for(;me(this.source,this.cache););return this.index<this.cache.values.length||me(this.source,this.cache)?s(this.cache.values[this.index++]):c()}};function L(e,t){return l(e),o(e,a(t),-1)}function R(e,t,n){let r=typeof t==`number`,i=r?e:0,a=r?t:e;if(!r&&n!==void 0)throw Error(`The "options" parameter must be the second argument when "start" is omitted`);let o=r?n:t;o!==void 0&&te(o,`options`);let{step:s=1,reverse:c=!1}=o??{};ee(s,`step`);let l=he(i,a,Math.abs(s),c);return l.length>0?new m(()=>new ge(l.first,l.step,l.length)):_()}function he(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 ge=class extends p{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 z(e,...t){if(l(e),t.length===1)return _e(e,t[0]);let[n,r]=t;u(r,`reducer`);let i=n,a=0;for(let t of e)i=r(i,t,a++);return i}function _e(e,t){u(t,`reducer`);let n,r=0;for(let i of e)n=r===0?i:t(n,i,r),r++;if(r===0)throw Error(`The "sourceIterable" must not be empty when "reduce" has no seed`);return n}function B(e,t){return d(t,`count`),g(t,t=>t>0?[e,t-1]:void 0)}function V(e,t){return l(e),d(t,`count`),new m(()=>new ve(e,t))}var ve=class extends h{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 H(e,t){return l(e),u(t,`predicate`),new m(()=>new ye(e,t))}var ye=class extends h{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 U(e,t){if(l(e),t===void 0){for(let t of e)return!0;return!1}u(t,`predicate`);let n=0;for(let r of e)if(t(r,n++))return!0;return!1}function W(e,t){return l(e),d(t,`count`),new m(()=>new be(e,t))}var be=class extends h{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 G(e,t){return l(e),u(t,`predicate`),new m(()=>new xe(e,t))}var xe=class extends h{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 K(e,t){return l(e),u(t,`tapper`),new m(()=>new Se(e,t))}var Se=class extends h{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 q(e,t){return l(e),u(t,`tapper`),new m(()=>(t(e,0),e[Symbol.iterator]()))}var Ce=n({collectToArray:()=>re,count:()=>f,distinct:()=>ae,empty:()=>_,every:()=>v,filter:()=>se,find:()=>y,findIndex:()=>b,flatMap:()=>x,forEach:()=>w,forEachAsync:()=>T,getMemoizeDefaultOptions:()=>j,includes:()=>E,map:()=>D,materialize:()=>O,max:()=>A,memoize:()=>M,min:()=>L,range:()=>R,reduce:()=>z,repeat:()=>B,skip:()=>V,skipWhile:()=>H,some:()=>U,take:()=>W,takeWhile:()=>G,tap:()=>K,tapChain:()=>q}),J=Symbol.for(`iterable-linq-utility.IIterableLinq`);function Y(e){return new X(e)}var X=class{iterable;constructor(e){this.iterable=e}[Symbol.iterator](){return this.iterable[Symbol.iterator]()}collectToArray(){return re(this.iterable)}count(e){return f(this.iterable,e)}distinct(e){return Y(ae(this.iterable,e))}every(e){return v(this.iterable,e)}filter(e){return Y(se(this.iterable,e))}find(e){return y(this.iterable,e)}findIndex(e){return b(this.iterable,e)}flatMap(e){return Y(x(this.iterable,e))}forEach(e){return w(this.iterable,e)}forEachAsync(e){return T(this.iterable,e)}includes(e){return E(this.iterable,e)}map(e){return Y(D(this.iterable,e))}materialize(){return Y(O(this.iterable))}max(e){return A(this.iterable,e)}memoize(e){return Y(M(this.iterable,e))}min(e){return L(this.iterable,e)}reduce(...e){return e.length===1?z(this.iterable,e[0]):z(this.iterable,e[0],e[1])}skip(e){return Y(V(this.iterable,e))}skipWhile(e){return Y(H(this.iterable,e))}some(e){return U(this.iterable,e)}take(e){return Y(W(this.iterable,e))}takeWhile(e){return Y(G(this.iterable,e))}tap(e){return Y(K(this.iterable,e))}tapChain(e){return Y(q(this.iterable,e))}tapChainCreation(e){u(e,`chainCreationTapper`);let t=this;return e(t),t}};Object.defineProperty(X.prototype,J,{value:!0,enumerable:!1,writable:!1,configurable:!1});function Z(){return X.prototype}function we(e){return typeof e==`object`&&!!e&&e[J]===!0}function Q(e,t){let n=Object.getOwnPropertyDescriptor(Z(),e);Object.defineProperty(Z(),e,{value:t,enumerable:!1,writable:n?.writable??!1,configurable:!0})}function Te(e,t){ne(e,`name`),u(t,`implementation`)}function Ee(e,t){if(Te(e,t),e in Y([]))throw Error(`"${e}" already exists on IIterableLinq: use override() to replace it`);Q(e,t)}function De(e,t){Te(e,t);let n=e;if(!(n!==`constructor`&&Object.prototype.hasOwnProperty.call(Z(),n)))throw Error(`"${n}" is not a method of IIterableLinq: use extend() to add it`);Q(n,t)}function Oe(){return $(_())}function $(e){return l(e),Y(e)}function ke(e,t,n){if(typeof t==`number`)return $(R(e,t,n));if(n!==void 0)throw Error(`The "options" parameter must be the second argument when "start" is omitted`);return $(R(e,t))}function Ae(e,t){return $(B(e,t))}Object.defineProperty(e,"Functions",{enumerable:!0,get:function(){return Ce}}),e.Unit=S,e.empty=Oe,e.extend=Ee,e.from=$,e.fromRange=ke,e.isIterableLinq=we,e.override=De,e.repeat=Ae,e.unit=C});
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iterable-linq-utility",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "An Iterable mutation utility inspired by .net Linq and Javascript Array interface",
5
5
  "type": "module",
6
6
  "main": "./dist/iterable-linq-utility.umd.cjs",