Deque<T> class

A double-ended queue (deque) that allows for insertion and deletion of elements at both the front and the rear.

This implementation uses ListQueue from dart:collection under the hood, which is designed to handle double-ended operations with very little friction.

Mixed-in types
Available extensions

Constructors

Deque()
Creates an empty deque.
Deque.from(Iterable<T> elements)
Creates a deque containing the elements of the given iterable.

Properties

first → T
The first element.
no setterinherited
firstOrNull → T?

Available on Iterable<T>, provided by the IterableExtensions extension

The first element of this iterator, or null if the iterable is empty.
no setter
hashCode int
The hash code for this object.
no setteroverride
indexed Iterable<(int, T)>

Available on Iterable<T>, provided by the IterableExtensions extension

Pairs of elements of the indices and elements of this iterable.
no setter
isEmpty bool
Returns true if the deque is empty.
no setteroverride
isNotEmpty bool
Returns true if the deque has at least one element.
no setteroverride
iterator Iterator<T>
A new Iterator that allows iterating the elements of this Iterable.
no setteroverride
last → T
The last element.
no setterinherited
lastOrNull → T?

Available on Iterable<T>, provided by the IterableExtensions extension

The last element of this iterable, or null if the iterable is empty.
no setter
length int
Returns the number of elements in the deque.
no setteroverride
nonNulls Iterable<T>

Available on Iterable<T?>, provided by the NullableIterableExtensions extension

The non-null elements of this iterable.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
single → T
Checks that this iterable has only one element, and returns that element.
no setterinherited
singleOrNull → T?

Available on Iterable<T>, provided by the IterableExtensions extension

The single element of this iterator, or null.
no setter
wait Future<List<T>>

Available on Iterable<Future<T>>, provided by the FutureIterable extension

Waits for futures in parallel.
no setter

Methods

any(bool test(T element)) bool
Checks whether any element of this iterable satisfies test.
inherited
asNameMap() Map<String, T>

Available on Iterable<T>, provided by the EnumByName extension

Creates a map from the names of enum values to the values.
at(int index) → T
Random access: retrieves the element at index. Note: O(N) complexity due to underlying ListQueue implementation.
back() → T
Returns the back element without removing it (C++ STL naming).
byName(String name) → T

Available on Iterable<T>, provided by the EnumByName extension

Finds the enum value in this list with name name.
cast<R>() Iterable<R>
A view of this iterable as an iterable of R instances.
inherited
clear() → void
Removes all elements from the deque.
contains(Object? element) bool
Whether the collection contains an element equal to element.
inherited
deleteFront() → T
Removes and returns the element at the front of the deque. Throws a StateError if the deque is empty.
deleteLast() → T
Removes and returns the element at the last (rear) of the deque. Throws a StateError if the deque is empty.
elementAt(int index) → T
Returns the indexth element.
inherited
elementAtOrNull(int index) → T?

Available on Iterable<T>, provided by the IterableExtensions extension

The element at position index of this iterable, or null.
every(bool test(T element)) bool
Checks whether every element of this iterable satisfies test.
inherited
expand<T>(Iterable<T> toElements(T element)) Iterable<T>
Expands each element of this Iterable into zero or more elements.
inherited
firstWhere(bool test(T element), {T orElse()?}) → T
The first element that satisfies the given predicate test.
inherited
fold<T>(T initialValue, T combine(T previousValue, T element)) → T
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value
inherited
followedBy(Iterable<T> other) Iterable<T>
Creates the lazy concatenation of this iterable and other.
inherited
forEach(void action(T element)) → void
Invokes action on each element of this iterable in iteration order.
inherited
front() → T
Returns the front element without removing it (C++ STL naming).
getFront() → T
Returns the element at the front of the deque without removing it. Throws a StateError if the deque is empty.
getRear() → T
Returns the element at the rear (last) of the deque without removing it. Throws a StateError if the deque is empty.
insertFront(T element) → void
Inserts an element at the front of the deque.
insertLast(T element) → void
Inserts an element at the last (rear) of the deque.
join([String separator = ""]) String
Converts each element to a String and concatenates the strings.
inherited
lastWhere(bool test(T element), {T orElse()?}) → T
The last element that satisfies the given predicate test.
inherited
map<T>(T toElement(T e)) Iterable<T>
The current elements of this iterable modified by toElement.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
popBack() → T
Removes and returns the back element (C++ STL naming).
popFront() → T
Removes and returns the front element (C++ STL naming).
pushBack(T element) → void
Adds an element to the back (C++ STL naming).
pushFront(T element) → void
Adds an element to the front (C++ STL naming).
reduce(T combine(T value, T element)) → T
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
inherited
singleWhere(bool test(T element), {T orElse()?}) → T
The single element that satisfies test.
inherited
skip(int count) Iterable<T>
Creates an Iterable that provides all but the first count elements.
inherited
skipWhile(bool test(T value)) Iterable<T>
Creates an Iterable that skips leading elements while test is satisfied.
inherited
swap(Deque<T> other) → void
Exchanges the contents of this deque with those of other.
take(int count) Iterable<T>
Creates a lazy iterable of the count first elements of this iterable.
inherited
takeWhile(bool test(T value)) Iterable<T>
Creates a lazy iterable of the leading elements satisfying test.
inherited
toList({bool growable = true}) List<T>
Creates a List containing the elements of this Iterable.
inherited
toSet() Set<T>
Creates a Set containing the same elements as this iterable.
inherited
toString() String
A string representation of this object.
override
where(bool test(T element)) Iterable<T>
Creates a new lazy Iterable with all elements that satisfy the predicate test.
inherited
whereType<T>() Iterable<T>
Creates a new lazy Iterable with all elements that have type T.
inherited

Operators

operator ==(Object other) bool
The equality operator.
override
operator [](int index) → T
Operator overload for random access.
operator []=(int index, T value) → void
Operator overload for setting an element at index. Note: O(N) complexity as it requires rebuilding parts of the queue.