AQueue is a collection that can be manipulated at both ends. Onecan iterate over the elements of a queue throughforEach or withanIterator.
It is generally not allowed to modify the queue (add or remove entries)while an operation in the queue is being performed, for example during acall toforEach.Modifying the queue while it is being iterated will most likely break theiteration.This goes both for using theiterator directly, or for iterating anIterable returned by a method likemap orwhere.
Example:
final queue = Queue<int>(); // ListQueue() by defaultprint(queue.runtimeType); // ListQueue// Adding items to queuequeue.addAll([1, 2, 3]);queue.addFirst(0);queue.addLast(10);print(queue); // {0, 1, 2, 3, 10}// Removing items from queuequeue.removeFirst();queue.removeLast();print(queue); // {1, 2, 3}- Implemented types
- Iterable<
E>
- Iterable<
- Implementers
- Available extensions
Constructors
- Queue()
- Creates a queue.factory
- Queue.from(Iterableelements)
- Creates a queue containing all
elements.factory - Queue.of(Iterable<
E> elements) - Creates a queue from
elements.factory
Properties
- first→ E
- The first element.no setterinherited
- firstOrNull→ T?
Available onIterable<
The first element of this iterator, orT> , provided by theIterableExtensions extensionnullif the iterable is empty.no setter- hashCode→int
- The hash code for this object.no setterinherited
- indexed→Iterable<
(int,T)> Available onIterable<
Pairs of elements of the indices and elements of this iterable.T> , provided by theIterableExtensions extensionno setter- isEmpty→bool
- Whether this collection has no elements.no setterinherited
- isNotEmpty→bool
- Whether this collection has at least one element.no setterinherited
- iterator→Iterator<
E> - A new
Iteratorthat allows iterating the elements of thisIterable.no setterinherited - last→ E
- The last element.no setterinherited
- lastOrNull→ T?
Available onIterable<
The last element of this iterable, orT> , provided by theIterableExtensions extensionnullif the iterable is empty.no setter- length→int
- The number of elements in thisIterable.no setterinherited
- nonNulls→Iterable<
T> Available onIterable<
The non-T?> , provided by theNullableIterableExtensions extensionnullelements of this iterable.no setter- runtimeType→Type
- A representation of the runtime type of the object.no setterinherited
- single→ E
- Checks that this iterable has only one element, and returns that element.no setterinherited
- singleOrNull→ T?
Available onIterable<
The single element of this iterator, orT> , provided by theIterableExtensions extensionnull.no setter- wait→Future<
List< T> > Available onIterable<
Waits for futures in parallel.Future< , provided by theFutureIterable extensionT> >no setter
Methods
- add(
Evalue)→ void - Adds
valueat the end of the queue. - addAll(
Iterable< E> iterable)→ void - Adds all elements of
iterableat the end of the queue. Thelength of the queue is extended by the length ofiterable. - addFirst(
Evalue)→ void - Adds
valueat the beginning of the queue. - addLast(
Evalue)→ void - Adds
valueat the end of the queue. - any(
booltest(Eelement))→bool - Checks whether any element of this iterable satisfies
test.inherited - asNameMap(
)→Map< String,T> Available onIterable<
Creates a map from the names of enum values to the values.T> , provided by theEnumByName extension- byName(
Stringname)→ T Available onIterable<
Finds the enum value in this list with nameT> , provided by theEnumByName extensionname.- cast<
R> ()→Queue< R> - Provides a view of this queue as a queue of
Rinstances, if necessary.override - clear(
)→ void - Removes all elements in the queue. The size of the queue becomes zero.
- contains(
Object?element)→bool - Whether the collection contains an element equal to
element.inherited - elementAt(
intindex)→ E - Returns the
indexth element.inherited - elementAtOrNull(
intindex)→ T? Available onIterable<
The element at positionT> , provided by theIterableExtensions extensionindexof this iterable, ornull.- every(
booltest(Eelement))→bool - Checks whether every element of this iterable satisfies
test.inherited - expand<
T> (Iterable< T> toElements(Eelement))→Iterable<T> - Expands each element of thisIterable into zero or more elements.inherited
- firstWhere(
booltest(Eelement), {EorElse()?})→ E - The first element that satisfies the given predicate
test.inherited - fold<
T> (TinitialValue,Tcombine(TpreviousValue,Eelement))→ T - Reduces a collection to a single value by iteratively combining eachelement of the collection with an existing valueinherited
- followedBy(
Iterable< E> other)→Iterable<E> - Creates the lazy concatenation of this iterable and
other.inherited - forEach(
voidaction(Eelement))→ void - Invokes
actionon each element of this iterable in iteration order.inherited - join(
[Stringseparator =""])→String - Converts each element to aString and concatenates the strings.inherited
- lastWhere(
booltest(Eelement), {EorElse()?})→ E - The last element that satisfies the given predicate
test.inherited - map<
T> (TtoElement(Ee))→Iterable< T> - The current elements of this iterable modified by
toElement.inherited - noSuchMethod(
Invocationinvocation)→ dynamic - Invoked when a nonexistent method or property is accessed.inherited
- reduce(
Ecombine(Evalue,Eelement))→ E - Reduces a collection to a single value by iteratively combining elementsof the collection using the provided function.inherited
- remove(
Object?value)→bool - Removes a single instance of
valuefrom the queue. - removeFirst(
)→ E - Removes and returns the first element of this queue.
- removeLast(
)→ E - Removes and returns the last element of the queue.
- removeWhere(
booltest(Eelement))→ void - Removes all elements matched by
testfrom the queue. - retainWhere(
booltest(Eelement))→ void - Removes all elements not matched by
testfrom the queue. - singleWhere(
booltest(Eelement), {EorElse()?})→ E - The single element that satisfies
test.inherited - skip(
intcount)→Iterable< E> - Creates anIterable that provides all but the first
countelements.inherited - skipWhile(
booltest(Evalue))→Iterable< E> - Creates an
Iterablethat skips leading elements whiletestis satisfied.inherited - take(
intcount)→Iterable< E> - Creates a lazy iterable of the
countfirst elements of this iterable.inherited - takeWhile(
booltest(Evalue))→Iterable< E> - Creates a lazy iterable of the leading elements satisfying
test.inherited - toList(
{boolgrowable =true})→List< E> - Creates aList containing the elements of thisIterable.inherited
- toSet(
)→Set< E> - Creates aSet containing the same elements as this iterable.inherited
- toString(
)→String - A string representation of this object.inherited
- where(
booltest(Eelement))→Iterable< E> - Creates a new lazyIterable with all elements that satisfy thepredicate
test.inherited - whereType<
T> ()→Iterable< T> - Creates a new lazyIterable with all elements that have type
T.inherited
Operators
- operator ==(
Objectother)→bool - The equality operator.inherited