class Iterator{list(){const t=[];for(;this.next();)t.push(this.current);return t}next(){return!1}peek(){return this.next()?this.current:void 0}map(e,n){null==n&&(n=function(t,r){return r});const i=this,u=new Iterator,o=u.next;return u.next=function(){for(;i.next();){const t=Iterator.from(e(i.current));if(t.next()){const r=u.next;return u.next=function(){return t.next()?(u.key=n(t.current,t.key),u.current=t.current,!0):(u.next=r,u.next())},u.key=n(t.current,t.key),u.current=t.current,!0}}return u.key=void 0,u.current=void 0,u.next=o,!1},u}filter(t){const r=this,e=new Iterator,n=e.next;return e.next=function(){for(;r.next();)if(t(r.current,r.key))return e.key=r.key,e.current=r.current,!0;return e.key=void 0,e.current=void 0,e.next=n,!1},e}concat(r){const e=this,n=new Iterator,i=n.next;return n.next=function(){if(e.next())return n.key=e.key,n.current=e.current,!0;const t=Iterator.from(r);return n.next=function(){return t.next()?(n.key=t.key,n.current=t.current,!0):(n.key=void 0,n.current=void 0,n.next=i,!1)},n.next()},n}static from(r){if(Array.isArray(r)){const e=new Iterator,n=e.next;return e.next=function(){let t=0;return e.next=function(){return t<r.length?(e.key=t,e.current=r[t++],!0):(e.key=t,e.current=void 0,e.next=n,!1)},e.next()},e}if(r instanceof Iterator)return r;const e=new Iterator,n=e.next;return e.next=function(){return e.current=r,e.next=function(){return e.current=void 0,e.next=n,!1},!0},e}}Iterator.empty=new Iterator;class Dictionary{constructor(){this.iterating=!1,this.array=[],this.lookup={}}ensureMutable(){let t=this.array;return this.iterating&&(t=this.array=[...t],this.iterating=!1),t}iterate(){const i=this,u=new Iterator,o=u.next;return u.next=function(){i.iterating?i.array=[...i.array]:i.iterating=!0;let e=0;const n=i.array;return u.next=function(){for(;e<n.length;){var t=n[e++],r=t.key;if(i.lookup[r]===t)return u.key=r,u.current=t.value,!0}return i.array===n&&(i.iterating=!1),u.key=void 0,u.current=void 0,u.next=o,!1},u.next()},u}assign(t,r){t=String(t);const e=this.lookup;var n=e[t];if(void 0!==n){var i=n.index,n=n.value;const u=this.ensureMutable();return u[i]=e[t]={key:t,index:i,value:r},n}const u=this.ensureMutable();u.push(e[t]={key:t,index:u.length,value:r})}remove(t){t=String(t);const r=this.lookup;var e=r[t];if(void 0!==e&&delete r[t]){t=e.index;const n=this.ensureMutable();e=n.length-1;if(t!==e){const i=n[e];n[i.index=t]=i}n.length=e}return!1}exists(t){return void 0!==this.lookup[String(t)]}find(t){t=this.lookup[String(t)];return void 0!==t?t.value:void 0}clear(){0<this.array.length&&(this.array=[],this.lookup={})}get length(){return this.array.length}}class Stash{constructor(){this.lookup={}}isArray(t){return Array.isArray(t)&&t.owner===this.lookup}read(t,r){t=this.lookup[String(t)];if(void 0!==t){if(!this.isArray(t))return t.item===r?t.result:void 0;for(const e of t)if(e.item===r)return e.result}}write(t,r,e){t=String(t);const n=this.lookup;let i=n[t];if(void 0!==i)if(this.isArray(i)){for(const s of i)if(s.item===r){var u=s.result;return s.result=e,u}i.push({item:r,result:e})}else{if(i.item===r){var o=i.result;return i.result=e,o}n[t]=i=[i,{item:r,result:e}],i.owner=n}else n[t]={item:r,result:e}}}export{Iterator,Dictionary,Stash};