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