UNPKG

@altostra/core

Version:

Core library for shared types and logic

1 lines 807 B
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ListNode=void 0;const Numerics_1=require("../../common/CustomTypes/Numerics"),AltoError_1=require("../../common/Errors/AltoError");class ListNode{constructor(t,e){var r;this.value=t,this.prev=e,this.length=(null!==(r=null==e?void 0:e.length)&&void 0!==r?r:0)+1}*[Symbol.iterator](){this.prev&&(yield*this.prev),yield this.value}append(...t){let e=this;for(const r of t)e=new ListNode(r,e);return e}pop(t=(0,Numerics_1.naturalNumber)(1)){if(t>this.length)throw AltoError_1.AltoError.create(`Cannot pop ${t} items from list of length ${this.length}`);if(t===this.length)return;let e=this;for(;t--;)e=null==e?void 0:e.prev;return e}static fromIterable(t){let e;for(const r of t)e=new ListNode(r,e);return e}}exports.ListNode=ListNode;