UNPKG

sussy-util

Version:
75 lines (74 loc) 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const _1 = require("."); class Queue { constructor(initElm) { this.items = new _1.ImprovedArray(); this.items.push(...initElm); } /** * The function takes a variable number of arguments of type T and pushes them into the items array * @param {any[]} elm - T[] */ push(...elm) { this.items.push(...elm); } /** * It returns the first element of the array * @returns The first item in the array. */ peek() { return _1.Optional.ofNullable(this.items[0]); } /** * It removes the first element from an array and returns that element * @returns The first element of the array. */ shift() { return _1.Optional.ofNullable(this.items.shift()); } /** * Returns true if the queue is empty, false otherwise * @returns The method returns a boolean value. */ empty() { return this.items.isEmpty(); } toString() { return `Queue: ${this.items.toString()}`; } /** * This function returns a copy of the items array. * @returns The clone of the items array. */ toArray() { return this.items.clone(); } /** * It takes the items array and converts it to a JSON string. * @returns The JSON string representation of the items array. */ toJSONString() { return JSON.stringify(this.items); } [Symbol.iterator]() { let index = 0; return { next: () => { if (index < this.items.length) { return { value: this.items[index++], done: false, }; } else { return { value: undefined, done: true, }; } }, }; } } exports.default = Queue;