UNPKG

metaapi.cloud-sdk

Version:

SDK for MetaApi, a professional cloud forex API which includes MetaTrader REST API and MetaTrader websocket API. Supports both MetaTrader 5 (MT5) and MetaTrader 4 (MT4). CopyFactory copy trading API included. (https://metaapi.cloud)

97 lines (96 loc) 2.85 kB
/** * Implements a queue structure * @template T Queue values type */ export default class Queue<T> { private _length; private _start; private _end; /** * Creates a queue from array * @param {Array<V>} array Array to create the queue from * @return {Queue<V>} Queue created from the array * @deprecated Use constructor instead */ static fromArray<V>(array: V[]): Queue<V>; /** * Constructs instance * @param {Iterable<T>} [items] Initial items to add to the queue */ constructor(items?: Iterable<T>); /** * Returns the queue size * @return {Number} Queue size */ get length(): number; /** * Iterates by queue items */ [Symbol.iterator](): Iterator<T>; /** * Returns the first element or undefined if the queue is empty * @return {T} The first value */ front(): T | undefined; /** * Returns the last element or undefined if the queue is empty * @return {T} The last value */ back(): T | undefined; /** * Pushes new elements to the end of the queue * @param {T[]} values Values to push */ push(...values: T[]): void; /** * Removes the last element from the queue * @return {T} The value removed or undefined */ pop(): T | undefined; /** * Inserts new elements to the front of the queue * @param {T} value Values to unshift */ unshift(value: T): void; /** * Removes the first element from the queue * @return {T} The value removed or undefined */ shift(): T | undefined; /** * Finds an element in the queue by the predicate * @param {(value: T) => boolean} predicate Predicate to use * @return {T} Element value found or undefined */ find(predicate: (value: T) => boolean): T | undefined; /** * Iterates over the queue * @param {(value: T, index: Number) => any} callable Iterator callable */ forEach(callable: (value: T, index: number) => any): void; /** * Removes elements iterating them and matching by predicate * @param {(value: T) => boolean|null} predicate Returns true for values to remove. If returns null, iteration stops */ remove(predicate: (value: T) => boolean | null): void; /** * Removes the first occurence of element matched by predicate * @param predicate returns true for value to removed */ removeOne(predicate: (value: T) => boolean): void; /** * Creates a new queue from this one in reversed order * @return {Queue<T>} Reversed queue */ reversed(): Queue<T>; /** * Creates an array from the queue * @return {Array<T>} Array created */ toArray(): T[]; /** * Clears the queue */ clear(): void; private _remove; }