iterable-linq-utility 0.7.0 → 0.9.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,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});
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 f(e,t,n){if(!Number.isInteger(e))throw l(n,`The "${t}" parameter must be an integer`)}function p(e,t,n){if(!Number.isInteger(e)||e<0)throw l(n,`The "${t}" parameter must be a non-negative integer`)}function ee(e,t,n){if(!Number.isFinite(e)||e===0)throw l(n,`The "${t}" parameter must be a finite number other than 0`)}function te(e,t,n){if(typeof e!=`object`||!e)throw l(n,`The "${t}" parameter must be an object`)}function ne(e,t,n){if(typeof e!=`string`||e.length===0)throw l(n,`The "${t}" parameter must be a non-empty string`)}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 re(e,t){return new h(()=>new ie(e,t))}var ie=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 ae(e,t){return u(e,`append`),new h(()=>new oe(e,t))}var oe=class extends g{value;sourceDone=!1;constructor(e,t){super(e),this.value=t}advance(){if(this.sourceDone)return c();let e=this.source.next();return e.done===!0?(this.sourceDone=!0,s(this.value)):e}};function se(e,t){return u(e,`at`),f(t,`index`,`at`),t>=0?ce(e,t):le(e,-t)}function ce(e,t){let n=0;for(let r of e)if(n++===t)return r}function le(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 ue(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 _(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 de(e,...t){u(e,`concat`);for(let e of t)u(e,`concat`);let n=[e,...t];return new h(()=>new fe(n))}var fe=class extends m{sources;position=0;current;constructor(e){super(),this.sources=e,this.current=e[0][Symbol.iterator]()}advance(){for(;;){let e=this.current.next();if(e.done!==!0||++this.position===this.sources.length)return e;this.current=void 0,this.current=this.sources[this.position][Symbol.iterator]()}}onReturn(e){this.current?.return?.(e)}};function v(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}function y(e,t){return u(e,`distinct`),t!==void 0&&d(t,`keySelector`,`distinct`),new h(()=>new pe(e,t))}var pe=class extends g{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 re(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 h(()=>new me(e,t))}var me=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 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 h(()=>new he(e,t))}var he=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}}},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 h(()=>new ge(e,t))}var ge=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 _e(e){u(e,`LinkedList.from`);let t=new L;for(let n of e)t.addLast(n);return t}var L=class{internalSize=0;head=null;tail=null;[Symbol.iterator](){return new ve(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}},ve=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 R(e){return u(e,`materialize`),e instanceof z?e:new z(e)}var z=class{source;constructor(e){this.source=_e(e)}[Symbol.iterator](){return this.source[Symbol.iterator]()}};function B(e,t){return u(e,`max`),o(e,a(t),1)}function V(){return{allowPartialMemoization:!0}}function H(e,t){u(e,`memoize`);let n={...V(),...t}.allowPartialMemoization;return e instanceof G?n?e.changePartialMemoizationBehaviour():e:e instanceof K?n?e:e.changePartialMemoizationBehaviour():n?new K(e):new G(e)}function U(){return{values:[],finished:!1}}function W(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 G=class{source;cache=U();constructor(e){this.source=e}[Symbol.iterator](){return new ye(this.source,this.cache,!0)}changePartialMemoizationBehaviour(){return new K(this.source)}},K=class{source;cache=U();constructor(e){this.source=e}[Symbol.iterator](){return new ye(this.source,this.cache,!1)}changePartialMemoizationBehaviour(){return new G(this.source)}},ye=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(;W(this.source,this.cache););return this.index<this.cache.values.length||W(this.source,this.cache)?s(this.cache.values[this.index++]):c()}};function be(e,t){return u(e,`min`),o(e,a(t),-1)}function xe(e,t){return u(e,`prepend`),new h(()=>new Se(e,t))}var Se=class extends g{value;valueYielded=!1;constructor(e,t){super(e),this.value=t}advance(){return this.valueYielded?this.source.next():(this.valueYielded=!0,s(this.value))}};function q(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&&te(o,`options`,`range`);let{step:s=1,reverse:c=!1}=o??{};ee(s,`step`,`range`);let u=Ce(i,a,Math.abs(s),c);return u.length>0?new h(()=>new we(u.first,u.step,u.length)):b()}function Ce(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 we=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 J(e,...t){if(u(e,`reduce`),t.length===1)return Te(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 Te(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 Ee(e,t){return p(t,`count`,`repeat`),re(t,t=>t>0?[e,t-1]:void 0)}function De(e){return u(e,`reverse`),new h(()=>new Oe(e))}var Oe=class extends g{reversed;advance(){return this.reversed??=this.fill(),this.reversed.next()}onReturn(e){this.reversed=void 0,super.onReturn(e)}fill(){let e=new L;for(let t=this.source.next();t.done!==!0;t=this.source.next())e.addFirst(t.value);return e[Symbol.iterator]()}};function ke(e,t){return e===t}function Ae(e,t,n){u(e,`sequenceEqual`),u(t,`sequenceEqual`),n!==void 0&&d(n,`equals`,`sequenceEqual`);let r=n??ke,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 je(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 Me(e,t){return u(e,`skip`),p(t,`count`,`skip`),new h(()=>new Ne(e,t))}var Ne=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 Y(e,t,n){u(e,`slice`),t!==void 0&&f(t,`start`,`slice`),n!==void 0&&f(n,`end`,`slice`);let r=t??0;if(r<0)return new h(()=>new Ie(e,-r,n));if(n!==void 0&&n<0)return new h(()=>new Fe(e,r,-n));let i=n===void 0?1/0:n>r?n:0;return new h(()=>new Pe(e,r,i))}var Pe=class extends g{start;end;constructor(e,t,n){super(e),this.start=t,this.end=n}advance(){if(this.index>=this.end)return this.source.return?.(),c();for(;this.index<this.start;){let e=this.source.next();if(e.done===!0)return e;this.index++}let e=this.source.next();return e.done!==!0&&this.index++,e}},Fe=class extends g{start;size;buffer=[];position=0;full=!1;constructor(e,t,n){super(e),this.start=t,this.size=n}advance(){for(;this.index<this.start;){let e=this.source.next();if(e.done===!0)return e;this.index++}for(let e=this.source.next();e.done!==!0;e=this.source.next()){if(this.full){let t=this.buffer[this.position];return this.store(e.value),s(t)}this.store(e.value)}return c()}store(e){this.buffer[this.position]=e,++this.position===this.size&&(this.position=0,this.full=!0)}},Ie=class extends g{size;end;buffer;position=0;remaining=0;constructor(e,t,n){super(e),this.size=t,this.end=n}advance(){if(this.buffer??=this.fill(),this.remaining===0)return this.buffer=[],c();this.remaining--;let e=this.buffer[this.position];return++this.position===this.buffer.length&&(this.position=0),s(e)}fill(){let e=[],t=0,n=0;for(let r=this.source.next();r.done!==!0;r=this.source.next())e[n]=r.value,t++,++n===this.size&&(n=0);let r=this.end===void 0?t:this.end<0?Math.max(t+this.end,0):Math.min(this.end,t);return this.position=t>this.size?n:0,this.remaining=Math.max(r-(t-e.length),0),e}};function Le(e,t){return u(e,`skipLast`),p(t,`count`,`skipLast`),t===0?Y(e):Y(e,0,-t)}function Re(e,t){return u(e,`skipWhile`),d(t,`predicate`,`skipWhile`),new h(()=>new ze(e,t))}var ze=class extends g{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 Be(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 Ve(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 He(e,t){return u(e,`take`),p(t,`count`,`take`),new h(()=>new Ue(e,t))}var Ue=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 We(e,t){return u(e,`takeLast`),p(t,`count`,`takeLast`),t===0?Y(e,0,0):Y(e,-t)}function Ge(e,t){return u(e,`takeWhile`),d(t,`predicate`,`takeWhile`),new h(()=>new Ke(e,t))}var Ke=class extends g{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 qe(e,t){return u(e,`tap`),d(t,`tapper`,`tap`),new h(()=>new Je(e,t))}var Je=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 Ye(e,t){return u(e,`tapChain`),d(t,`tapper`,`tapChain`),new h(()=>(t(e,0),e[Symbol.iterator]()))}var Xe=n({append:()=>ae,at:()=>se,average:()=>ue,collectToArray:()=>_,concat:()=>de,count:()=>v,distinct:()=>y,empty:()=>b,every:()=>x,filter:()=>S,find:()=>C,findIndex:()=>w,findLast:()=>T,findLastIndex:()=>E,flatMap:()=>D,forEach:()=>A,forEachAsync:()=>j,getMemoizeDefaultOptions:()=>V,includes:()=>M,indexOf:()=>N,join:()=>P,lastIndexOf:()=>F,map:()=>I,materialize:()=>R,max:()=>B,memoize:()=>H,min:()=>be,prepend:()=>xe,range:()=>q,reduce:()=>J,repeat:()=>Ee,reverse:()=>De,sequenceEqual:()=>Ae,single:()=>je,skip:()=>Me,skipLast:()=>Le,skipWhile:()=>Re,slice:()=>Y,some:()=>Be,sum:()=>Ve,take:()=>He,takeLast:()=>We,takeWhile:()=>Ge,tap:()=>qe,tapChain:()=>Ye}),Ze=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]()}append(e){return X(ae(this.iterable,e))}at(e){return se(this.iterable,e)}average(e){return ue(this.iterable,e)}collectToArray(){return _(this.iterable)}concat(...e){return X(de(this.iterable,...e))}count(e){return v(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)}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(R(this.iterable))}max(e){return B(this.iterable,e)}memoize(e){return X(H(this.iterable,e))}min(e){return be(this.iterable,e)}prepend(e){return X(xe(this.iterable,e))}reduce(...e){return e.length===1?J(this.iterable,e[0]):J(this.iterable,e[0],e[1])}reverse(){return X(De(this.iterable))}sequenceEqual(e,t){return Ae(this.iterable,e,t)}single(e){return je(this.iterable,e)}skip(e){return X(Me(this.iterable,e))}skipLast(e){return X(Le(this.iterable,e))}skipWhile(e){return X(Re(this.iterable,e))}slice(e,t){return X(Y(this.iterable,e,t))}some(e){return Be(this.iterable,e)}sum(e){return Ve(this.iterable,e)}take(e){return X(He(this.iterable,e))}takeLast(e){return X(We(this.iterable,e))}takeWhile(e){return X(Ge(this.iterable,e))}tap(e){return X(qe(this.iterable,e))}tapChain(e){return X(Ye(this.iterable,e))}tapChainCreation(e){d(e,`chainCreationTapper`,`tapChainCreation`);let t=this;return e(t),t}};Object.defineProperty(Z.prototype,Ze,{value:!0,enumerable:!1,writable:!1,configurable:!1});function Q(){return Z.prototype}function Qe(e){return typeof e==`object`&&!!e&&e[Ze]===!0}function $e(e,t){let n=Object.getOwnPropertyDescriptor(Q(),e);Object.defineProperty(Q(),e,{value:t,enumerable:!1,writable:n?.writable??!1,configurable:!0})}function et(e,t,n){ne(t,`name`,e),d(n,`implementation`,e)}function tt(e,t){if(et(`extend`,e,t),e in X([]))throw l(`extend`,`"${e}" already exists on IIterableLinq: use override() to replace it`);$e(e,t)}function nt(e,t){et(`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`);$e(n,t)}function rt(){return $(b())}function $(e){return u(e,`from`),X(e)}function it(e,t,n){if(typeof t==`number`)return $(q(e,t,n));if(n!==void 0)throw l(`fromRange`,`The "options" parameter must be the second argument when "start" is omitted`);return $(q(e,t))}function at(e,t){return $(Ee(e,t))}Object.defineProperty(e,"Functions",{enumerable:!0,get:function(){return Xe}}),e.Unit=O,e.empty=rt,e.extend=tt,e.from=$,e.fromRange=it,e.isIterableLinq=Qe,e.override=nt,e.repeat=at,e.unit=k});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iterable-linq-utility",
3
- "version": "0.7.0",
3
+ "version": "0.9.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",
@@ -37,6 +37,7 @@
37
37
  "test": "vitest run",
38
38
  "bench": "vite build --logLevel error && vitest bench --run",
39
39
  "bench:baseline": "vite build --logLevel error && BENCH_SAVE=1 vitest bench --run",
40
+ "bench:report": "node scripts/bench-report.ts",
40
41
  "test:coverage": "vitest run --coverage",
41
42
  "test:ui": "vitest --ui"
42
43
  },