Queue - acadet/ludivine GitHub Wiki

Queue<T>
|> ISortableCollection<T>
    |> ICollection<T>

A classic queue structure (FIFO).

NB: Browsers always move from oldest to newest element.

References

Constructors

Queue<T>()

Builds new queue.

Queue<T>(source : ICollection<T>)

Builds new queue.

Parameters

source Data source


Methods

average(getter : Func<T, number>) : number

Inherited from ICollection.

exists(selector : Func<T, boolean>) : boolean

Inherited from ICollection.

find(selector : Func<T, boolean>) : T

Inherited from ICollection.

forEach(action : Action<T>) : void

Inherited from ICollection.

Example

queue.push('foo');
queue.push('bar');
queue.push('foobar');

queue.forEach(x => console.log(x)); // foo | bar | foobar
getSize() : number

Returns current size.

intersect(collection : ICollection<T>) : ICollection<T>

Inherited from ICollection.

map(action : Func<T, T>) : ICollection<T>

Inherited from ICollection.

max(getter : Func<T, number>) : T

Inherited from ICollection.

min(getter : Func<T, number>) : T

Inherited from ICollection.

orderBy<U>(getter : Func<T, U>) : ISortableCollection<T>

Inherited from ISortableCollection.

Ordering queue produces a new queue where oldest element is the lowest.

Example

queue.push(56);
queue.push(45);
queue.push(47);

orderedQueue = queue.orderBy(x => x);
// orderedQueue = 45 | 47 | 56
// orderedQueue.top() = 45
orderByDesc<U>(getter : Func<T, U>) : ISortableCollection<T>

Inherited from ISortableCollection.

Ordering queue using descending method produces a queue where oldest element is the greatest.

Example

queue.push(56);
queue.push(45);
queue.push(47);

orderedQueue = queue.orderByDesc(x => x);
// orderedQueue = 56 | 47 | 45
// orderedQueue.top() = 56
pop() : T

Gets oldest element and removes it from queue.

push(value : T) : void

Adds element in queue.

Parameters

value Value

reverse() : ISortableCollection<T>

Inherited from ISortableCollection.

select(selector : Func<T, boolean>) : ICollection<T>

Inherited from ICollection.

sum(getter : Func<T, number>) : number

Inherited from ICollection.

toArray() : Array<T>

Inherited from ICollection.

Array first element is oldest element of queue.

Example

queue.push('foo');
queue.push('bar');
queue.push('foobar');

a = queue.toArray(); // foo | bar | foobar
toDictionary<K, V>(keyGetter : Func<T, K>, valueGetter : Func<T, V>) : IDictionary<K, V>

Inherited from ICollection.

toList() : IList<T>

Inherited from ICollection.

List first element is oldest element of queue.

Example

queue.push('foo');
queue.push('bar');
queue.push('foobar');

l = queue.toList(); // foo | bar | foobar
top() : T

Gets oldest element without removing it from queue.

union(collection : ICollection<T>) : ICollection<T>

Inherited from ICollection.

Extra elements from data source are appended to queue.

Example

q1.push(10);
q1.push(11);
q2.push(20);
q2.push(21);

q3 = q1.union(q2); // 10 | 11 | 20 | 21
// q3.top() = 10
uniq() : ICollection<T>

Inherited from ICollection.

Removes from oldest to newest.

Example

q.push(10);
q.push(20);
q.push(20);
q.push(30);
q.push(10);

p = q.uniq(); // 10 | 20 | 30
// p.top() = 10
⚠️ **GitHub.com Fallback** ⚠️