UNPKG

di-tory

Version:

Compose applications with dependency injection

34 lines (33 loc) 902 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Stack = void 0; const StackError_js_1 = require("./StackError.js"); class Stack { constructor(items = [], set = new Set()) { this.items = items; this.set = set; } push(item) { if (this.set.has(item)) throw new StackError_js_1.StackError(StackError_js_1.StackErrorType.Exists); this.items.push(item); this.set.add(item); } pop() { const item = this.items.pop(); if (item == null) throw new StackError_js_1.StackError(StackError_js_1.StackErrorType.Empty); this.set.delete(item); return item; } peek() { return this.items.at(-1); } toStringArray() { return this.items.map(String); } get length() { return this.items.length; } } exports.Stack = Stack;