Appearance
LinkedList<E extends LinkedListEntry<E>> base
base class LinkedList<E extends LinkedListEntry<E>> extends Iterable<E>A specialized double-linked list of elements that extends LinkedListEntry.
This is not a generic data structure. It only accepts elements that extend the LinkedListEntry class. See the Queue implementations for generic collections that allow constant time adding and removing at the ends.
This is not a List implementation. Despite its name, this class does not implement the List interface. It does not allow constant time lookup by index.
Because the elements themselves contain the links of this linked list, each element can be in only one list at a time. To add an element to another list, it must first be removed from its current list (if any). For the same reason, the remove and contains methods are based on identity, even if the LinkedListEntry chooses to override Object.==.
In return, each element knows its own place in the linked list, as well as which list it is in. This allows constant time LinkedListEntry.insertAfter, LinkedListEntry.insertBefore and LinkedListEntry.unlink operations when all you have is the element.
A LinkedList also allows constant time adding and removing at either end, and a constant time length getter.
Example:
dart
final class EntryItem extends LinkedListEntry<EntryItem> {
final int id;
final String text;
EntryItem(this.id, this.text);
@override
String toString() {
return '$id : $text';
}
}
void main() {
final linkedList = LinkedList<EntryItem>();
linkedList
.addAll([EntryItem(1, 'A'), EntryItem(2, 'B'), EntryItem(3, 'C')]);
print(linkedList.first); // 1 : A
print(linkedList.last); // 3 : C
// Add new item after first item.
linkedList.first.insertAfter(EntryItem(15, 'E'));
// Add new item before last item.
linkedList.last.insertBefore(EntryItem(10, 'D'));
// Iterate items.
for (var entry in linkedList) {
print(entry);
// 1 : A
// 15 : E
// 2 : B
// 10 : D
// 3 : C
}
// Remove item using index from list.
linkedList.elementAt(2).unlink();
print(linkedList); // (1 : A, 15 : E, 10 : D, 3 : C)
// Remove first item.
linkedList.first.unlink();
print(linkedList); // (15 : E, 10 : D, 3 : C)
// Remove last item from list.
linkedList.remove(linkedList.last);
print(linkedList); // (15 : E, 10 : D)
// Remove all items.
linkedList.clear();
print(linkedList.length); // 0
print(linkedList.isEmpty); // true
}Inheritance
Object → Iterable<E> → LinkedList<E extends LinkedListEntry<E>>
Constructors
LinkedList()
LinkedList()Constructs a new empty linked list.
Implementation
dart
LinkedList();Properties
first no setter override
E get firstThe first element.
Throws a StateError if this is empty. Otherwise returns the first element in the iteration order, equivalent to this.elementAt(0).
Implementation
dart
E get first {
if (isEmpty) {
throw StateError('No such element');
}
return _first!;
}hashCode no setter inherited
int get hashCodeThe hash code for this object.
A hash code is a single integer which represents the state of the object that affects operator == comparisons.
All objects have hash codes. The default hash code implemented by Object represents only the identity of the object, the same way as the default operator == implementation only considers objects equal if they are identical (see identityHashCode).
If operator == is overridden to use the object state instead, the hash code must also be changed to represent that state, otherwise the object cannot be used in hash based data structures like the default Set and Map implementations.
Hash codes must be the same for objects that are equal to each other according to operator ==. The hash code of an object should only change if the object changes in a way that affects equality. There are no further requirements for the hash codes. They need not be consistent between executions of the same program and there are no distribution guarantees.
Objects that are not equal are allowed to have the same hash code. It is even technically allowed that all instances have the same hash code, but if clashes happen too often, it may reduce the efficiency of hash-based data structures like HashSet or HashMap.
If a subclass overrides hashCode, it should override the operator == operator as well to maintain consistency.
Inherited from Object.
Implementation
dart
external int get hashCode;isEmpty no setter override
bool get isEmptyWhether this collection has no elements.
May be computed by checking if iterator.moveNext() returns false.
Example:
dart
final emptyList = <int>[];
print(emptyList.isEmpty); // true;
print(emptyList.iterator.moveNext()); // falseImplementation
dart
bool get isEmpty => _length == 0;isNotEmpty no setter inherited
bool get isNotEmptyWhether this collection has at least one element.
May be computed by checking if iterator.moveNext() returns true.
Example:
dart
final numbers = <int>{1, 2, 3};
print(numbers.isNotEmpty); // true;
print(numbers.iterator.moveNext()); // trueInherited from Iterable.
Implementation
dart
bool get isNotEmpty => !isEmpty;iterator no setter override
Iterator<E> get iteratorA new Iterator that allows iterating the elements of this Iterable.
Iterable classes may specify the iteration order of their elements (for example List always iterate in index order), or they may leave it unspecified (for example a hash-based Set may iterate in any order).
Each time iterator is read, it returns a new iterator, which can be used to iterate through all the elements again. The iterators of the same iterable can be stepped through independently, but should return the same elements in the same order, as long as the underlying collection isn't changed.
Modifying the collection may cause new iterators to produce different elements, and may change the order of existing elements. A List specifies its iteration order precisely, so modifying the list changes the iteration order predictably. A hash-based Set may change its iteration order completely when adding a new element to the set.
Modifying the underlying collection after creating the new iterator may cause an error the next time Iterator.moveNext is called on that iterator. Any modifiable iterable class should specify which operations will break iteration.
Implementation
dart
Iterator<E> get iterator => _LinkedListIterator<E>(this);last no setter override
E get lastThe last element.
Throws a StateError if this is empty. Otherwise may iterate through the elements and returns the last one seen. Some iterables may have more efficient ways to find the last element (for example a list can directly access the last element, without iterating through the previous ones).
Implementation
dart
E get last {
if (isEmpty) {
throw StateError('No such element');
}
return _first!._previous!;
}length no setter override
int get lengthThe number of elements in this Iterable.
Counting all elements may involve iterating through all elements and can therefore be slow. Some iterables have a more efficient way to find the number of elements. These must override the default implementation of length.
Implementation
dart
int get length => _length;runtimeType no setter inherited
Type get runtimeTypeA representation of the runtime type of the object.
Inherited from Object.
Implementation
dart
external Type get runtimeType;single no setter override
E get singleChecks that this iterable has only one element, and returns that element.
Throws a StateError if this is empty or has more than one element. This operation will not iterate past the second element.
Implementation
dart
E get single {
if (isEmpty) {
throw StateError('No such element');
}
if (_length > 1) {
throw StateError('Too many elements');
}
return _first!;
}Methods
add()
void add(E entry)Adds entry to the end of the linked list.
Implementation
dart
void add(E entry) {
_insertBefore(_first, entry, updateFirst: false);
}addAll()
void addAll(Iterable<E> entries)Adds entries to the end of the linked list.
Implementation
dart
void addAll(Iterable<E> entries) {
entries.forEach(add);
}addFirst()
void addFirst(E entry)Adds entry to the beginning of the linked list.
Implementation
dart
void addFirst(E entry) {
_insertBefore(_first, entry, updateFirst: true);
_first = entry;
}any() inherited
Checks whether any element of this iterable satisfies test.
Checks every element in iteration order, and returns true if any of them make test return true, otherwise returns false. Returns false if the iterable is empty.
Example:
dart
final numbers = <int>[1, 2, 3, 5, 6, 7];
var result = numbers.any((element) => element >= 5); // true;
result = numbers.any((element) => element >= 10); // false;Inherited from Iterable.
Implementation
dart
bool any(bool test(E element)) {
for (E element in this) {
if (test(element)) return true;
}
return false;
}cast() inherited
Iterable<T> cast<R>()A view of this iterable as an iterable of R instances.
If this iterable only contains instances of R, all operations will work correctly. If any operation tries to access an element that is not an instance of R, the access will throw instead.
When the returned iterable creates a new object that depends on the type R, e.g., from toList, it will have exactly the type R.
Inherited from Iterable.
Implementation
dart
Iterable<R> cast<R>() => CastIterable<E, R>(this);clear()
void clear()Remove all elements from this linked list.
Implementation
dart
void clear() {
_modificationCount++;
if (isEmpty) return;
E next = _first!;
do {
E entry = next;
next = entry._next!;
entry._next = entry._previous = entry._list = null;
} while (!identical(next, _first));
_first = null;
_length = 0;
}contains() override
Whether entry is a LinkedListEntry belonging to this list.
The entry is considered as belonging to this list if its LinkedListEntry.list is this list.
Implementation
dart
bool contains(Object? entry) =>
entry is LinkedListEntry && identical(this, entry.list);elementAt() inherited
E elementAt(int index)Returns the indexth element.
The index must be non-negative and less than length. Index zero represents the first element (so iterable.elementAt(0) is equivalent to iterable.first).
May iterate through the elements in iteration order, ignoring the first index elements and then returning the next. Some iterables may have a more efficient way to find the element.
Example:
dart
final numbers = <int>[1, 2, 3, 5, 6, 7];
final elementAt = numbers.elementAt(4); // 6Inherited from Iterable.
Implementation
dart
E elementAt(int index) {
RangeError.checkNotNegative(index, "index");
var iterator = this.iterator;
var skipCount = index;
while (iterator.moveNext()) {
if (skipCount == 0) return iterator.current;
skipCount--;
}
throw IndexError.withLength(
index,
index - skipCount,
indexable: this,
name: "index",
);
}every() inherited
Checks whether every element of this iterable satisfies test.
Checks every element in iteration order, and returns false if any of them make test return false, otherwise returns true. Returns true if the iterable is empty.
Example:
dart
final planetsByMass = <double, String>{0.06: 'Mercury', 0.81: 'Venus',
0.11: 'Mars'};
// Checks whether all keys are smaller than 1.
final every = planetsByMass.keys.every((key) => key < 1.0); // trueInherited from Iterable.
Implementation
dart
bool every(bool test(E element)) {
for (E element in this) {
if (!test(element)) return false;
}
return true;
}expand() inherited
Expands each element of this Iterable into zero or more elements.
The resulting Iterable runs through the elements returned by toElements for each element of this, in iteration order.
The returned Iterable is lazy, and calls toElements for each element of this iterable every time the returned iterable is iterated.
Example:
dart
Iterable<int> count(int n) sync* {
for (var i = 1; i <= n; i++) {
yield i;
}
}
var numbers = [1, 3, 0, 2];
print(numbers.expand(count)); // (1, 1, 2, 3, 1, 2)Equivalent to:
dart
Iterable<T> expand<T>(Iterable<T> toElements(E e)) sync* {
for (var value in this) {
yield* toElements(value);
}
}Inherited from Iterable.
Implementation
dart
Iterable<T> expand<T>(Iterable<T> toElements(E element)) =>
ExpandIterable<E, T>(this, toElements);firstWhere() inherited
E firstWhere(bool Function(E element) test, {(E Function())? orElse})The first element that satisfies the given predicate test.
Iterates through elements and returns the first to satisfy test.
Example:
dart
final numbers = <int>[1, 2, 3, 5, 6, 7];
var result = numbers.firstWhere((element) => element < 5); // 1
result = numbers.firstWhere((element) => element > 5); // 6
result =
numbers.firstWhere((element) => element > 10, orElse: () => -1); // -1If no element satisfies test, the result of invoking the orElse function is returned. If orElse is omitted, it defaults to throwing a StateError. Stops iterating on the first matching element.
Inherited from Iterable.
Implementation
dart
E firstWhere(bool test(E element), {E orElse()?}) {
for (E element in this) {
if (test(element)) return element;
}
if (orElse != null) return orElse();
throw IterableElementError.noElement();
}fold() inherited
T fold<T>(T initialValue, T Function(T previousValue, E element) combine)Reduces a collection to a single value by iteratively combining each element of the collection with an existing value
Uses initialValue as the initial value, then iterates through the elements and updates the value with each element using the combine function, as if by:
dart
var value = initialValue;
for (E element in this) {
value = combine(value, element);
}
return value;Example of calculating the sum of an iterable:
dart
final numbers = <double>[10, 2, 5, 0.5];
const initialValue = 100.0;
final result = numbers.fold<double>(
initialValue, (previousValue, element) => previousValue + element);
print(result); // 117.5Inherited from Iterable.
Implementation
dart
T fold<T>(T initialValue, T combine(T previousValue, E element)) {
var value = initialValue;
for (E element in this) value = combine(value, element);
return value;
}followedBy() inherited
Creates the lazy concatenation of this iterable and other.
The returned iterable will provide the same elements as this iterable, and, after that, the elements of other, in the same order as in the original iterables.
Example:
dart
var planets = <String>['Earth', 'Jupiter'];
var updated = planets.followedBy(['Mars', 'Venus']);
print(updated); // (Earth, Jupiter, Mars, Venus)Inherited from Iterable.
Implementation
dart
Iterable<E> followedBy(Iterable<E> other) {
var self = this; // TODO(lrn): Remove when we can promote `this`.
if (self is EfficientLengthIterable<E>) {
return FollowedByIterable<E>.firstEfficient(self, other);
}
return FollowedByIterable<E>(this, other);
}forEach() override
void forEach(void Function(E entry) action)Call action with each entry in this linked list.
It's an error if action modifies the linked list.
Implementation
dart
void forEach(void action(E entry)) {
int modificationCount = _modificationCount;
if (isEmpty) return;
E current = _first!;
do {
action(current);
if (modificationCount != _modificationCount) {
throw ConcurrentModificationError(this);
}
current = current._next!;
} while (!identical(current, _first));
}join() inherited
Converts each element to a String and concatenates the strings.
Iterates through elements of this iterable, converts each one to a String by calling Object.toString, and then concatenates the strings, with the separator string interleaved between the elements.
Example:
dart
final planetsByMass = <double, String>{0.06: 'Mercury', 0.81: 'Venus',
0.11: 'Mars'};
final joinedNames = planetsByMass.values.join('-'); // Mercury-Venus-MarsInherited from Iterable.
Implementation
dart
String join([String separator = ""]) {
Iterator<E> iterator = this.iterator;
if (!iterator.moveNext()) return "";
var first = iterator.current.toString();
if (!iterator.moveNext()) return first;
var buffer = StringBuffer(first);
// TODO(51681): Drop null check when de-supporting pre-2.12 code.
if (separator == null || separator.isEmpty) {
do {
buffer.write(iterator.current.toString());
} while (iterator.moveNext());
} else {
do {
buffer
..write(separator)
..write(iterator.current.toString());
} while (iterator.moveNext());
}
return buffer.toString();
}lastWhere() inherited
E lastWhere(bool Function(E element) test, {(E Function())? orElse})The last element that satisfies the given predicate test.
An iterable that can access its elements directly may check its elements in any order (for example a list starts by checking the last element and then moves towards the start of the list). The default implementation iterates elements in iteration order, checks test(element) for each, and finally returns that last one that matched.
Example:
dart
final numbers = <int>[1, 2, 3, 5, 6, 7];
var result = numbers.lastWhere((element) => element < 5); // 3
result = numbers.lastWhere((element) => element > 5); // 7
result = numbers.lastWhere((element) => element > 10,
orElse: () => -1); // -1If no element satisfies test, the result of invoking the orElse function is returned. If orElse is omitted, it defaults to throwing a StateError.
Inherited from Iterable.
Implementation
dart
E lastWhere(bool test(E element), {E orElse()?}) {
var iterator = this.iterator;
// Potential result during first loop.
E result;
do {
if (!iterator.moveNext()) {
if (orElse != null) return orElse();
throw IterableElementError.noElement();
}
result = iterator.current;
} while (!test(result));
// Now `result` is actual result, unless a later one is found.
while (iterator.moveNext()) {
var current = iterator.current;
if (test(current)) result = current;
}
return result;
}map() inherited
Iterable<T> map<T>(T Function(E e) toElement)The current elements of this iterable modified by toElement.
Returns a new lazy Iterable with elements that are created by calling toElement on each element of this Iterable in iteration order.
The returned iterable is lazy, so it won't iterate the elements of this iterable until it is itself iterated, and then it will apply toElement to create one element at a time. The converted elements are not cached. Iterating multiple times over the returned Iterable will invoke the supplied toElement function once per element for on each iteration.
Methods on the returned iterable are allowed to omit calling toElement on any element where the result isn't needed. For example, elementAt may call toElement only once.
Equivalent to:
dart
Iterable<T> map<T>(T toElement(E e)) sync* {
for (var value in this) {
yield toElement(value);
}
}Example:
dart
var products = jsonDecode('''
[
{"name": "Screwdriver", "price": 42.00},
{"name": "Wingnut", "price": 0.50}
]
''');
var values = products.map((product) => product['price'] as double);
var totalPrice = values.fold(0.0, (a, b) => a + b); // 42.5.Inherited from Iterable.
Implementation
dart
Iterable<T> map<T>(T toElement(E e)) => MappedIterable<E, T>(this, toElement);noSuchMethod() inherited
dynamic noSuchMethod(Invocation invocation)Invoked when a nonexistent method or property is accessed.
A dynamic member invocation can attempt to call a member which doesn't exist on the receiving object. Example:
dart
dynamic object = 1;
object.add(42); // Statically allowed, run-time errorThis invalid code will invoke the noSuchMethod method of the integer 1 with an Invocation representing the .add(42) call and arguments (which then throws).
Classes can override noSuchMethod to provide custom behavior for such invalid dynamic invocations.
A class with a non-default noSuchMethod invocation can also omit implementations for members of its interface. Example:
dart
class MockList<T> implements List<T> {
noSuchMethod(Invocation invocation) {
log(invocation);
super.noSuchMethod(invocation); // Will throw.
}
}
void main() {
MockList().add(42);
}This code has no compile-time warnings or errors even though the MockList class has no concrete implementation of any of the List interface methods. Calls to List methods are forwarded to noSuchMethod, so this code will log an invocation similar to Invocation.method(#add, [42]) and then throw.
If a value is returned from noSuchMethod, it becomes the result of the original invocation. If the value is not of a type that can be returned by the original invocation, a type error occurs at the invocation.
The default behavior is to throw a NoSuchMethodError.
Inherited from Object.
Implementation
dart
@pragma("vm:entry-point")
@pragma("wasm:entry-point")
external dynamic noSuchMethod(Invocation invocation);reduce() inherited
E reduce(E Function(E value, E element) combine)Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
The iterable must have at least one element. If it has only one element, that element is returned.
Otherwise this method starts with the first element from the iterator, and then combines it with the remaining elements in iteration order, as if by:
dart
E value = iterable.first;
iterable.skip(1).forEach((element) {
value = combine(value, element);
});
return value;Example of calculating the sum of an iterable:
dart
final numbers = <double>[10, 2, 5, 0.5];
final result = numbers.reduce((value, element) => value + element);
print(result); // 17.5Consider using fold if the iterable can be empty.
Inherited from Iterable.
Implementation
dart
E reduce(E combine(E value, E element)) {
Iterator<E> iterator = this.iterator;
if (!iterator.moveNext()) {
throw IterableElementError.noElement();
}
E value = iterator.current;
while (iterator.moveNext()) {
value = combine(value, iterator.current);
}
return value;
}remove()
bool remove(E entry)Removes entry from the linked list.
Returns false and does nothing if entry is not in this linked list.
This is equivalent to calling entry.unlink() if the entry is in this list.
Implementation
dart
bool remove(E entry) {
if (entry._list != this) return false;
_unlink(entry); // Unlink will decrement length.
return true;
}singleWhere() inherited
E singleWhere(bool Function(E element) test, {(E Function())? orElse})The single element that satisfies test.
Checks elements to see if test(element) returns true. If exactly one element satisfies test, that element is returned. If more than one matching element is found, throws StateError. If no matching element is found, returns the result of orElse. If orElse is omitted, it defaults to throwing a StateError.
Example:
dart
final numbers = <int>[2, 2, 10];
var result = numbers.singleWhere((element) => element > 5); // 10When no matching element is found, the result of calling orElse is returned instead.
dart
result = numbers.singleWhere((element) => element == 1,
orElse: () => -1); // -1There must not be more than one matching element.
dart
result = numbers.singleWhere((element) => element == 2); // Throws Error.Inherited from Iterable.
Implementation
dart
E singleWhere(bool test(E element), {E orElse()?}) {
var iterator = this.iterator;
E result;
do {
if (!iterator.moveNext()) {
if (orElse != null) return orElse();
throw IterableElementError.noElement();
}
result = iterator.current;
} while (!test(result));
while (iterator.moveNext()) {
if (test(iterator.current)) throw IterableElementError.tooMany();
}
return result;
}skip() inherited
Creates an Iterable that provides all but the first count elements.
When the returned iterable is iterated, it starts iterating over this, first skipping past the initial count elements. If this has fewer than count elements, then the resulting Iterable is empty. After that, the remaining elements are iterated in the same order as in this iterable.
Some iterables may be able to find later elements without first iterating through earlier elements, for example when iterating a List. Such iterables are allowed to ignore the initial skipped elements.
Example:
dart
final numbers = <int>[1, 2, 3, 5, 6, 7];
final result = numbers.skip(4); // (6, 7)
final skipAll = numbers.skip(100); // () - no elements.The count must not be negative.
Inherited from Iterable.
Implementation
dart
Iterable<E> skip(int count) => SkipIterable<E>(this, count);skipWhile() inherited
Creates an Iterable that skips leading elements while test is satisfied.
The filtering happens lazily. Every new Iterator of the returned iterable iterates over all elements of this.
The returned iterable provides elements by iterating this iterable, but skipping over all initial elements where test(element) returns true. If all elements satisfy test the resulting iterable is empty, otherwise it iterates the remaining elements in their original order, starting with the first element for which test(element) returns false.
Example:
dart
final numbers = <int>[1, 2, 3, 5, 6, 7];
var result = numbers.skipWhile((x) => x < 5); // (5, 6, 7)
result = numbers.skipWhile((x) => x != 3); // (3, 5, 6, 7)
result = numbers.skipWhile((x) => x != 4); // ()
result = numbers.skipWhile((x) => x.isOdd); // (2, 3, 5, 6, 7)Inherited from Iterable.
Implementation
dart
Iterable<E> skipWhile(bool test(E value)) => SkipWhileIterable<E>(this, test);take() inherited
Creates a lazy iterable of the count first elements of this iterable.
The returned Iterable may contain fewer than count elements, if this contains fewer than count elements.
The elements can be computed by stepping through iterator until count elements have been seen.
The count must not be negative.
Example:
dart
final numbers = <int>[1, 2, 3, 5, 6, 7];
final result = numbers.take(4); // (1, 2, 3, 5)
final takeAll = numbers.take(100); // (1, 2, 3, 5, 6, 7)Inherited from Iterable.
Implementation
dart
Iterable<E> take(int count) => TakeIterable<E>(this, count);takeWhile() inherited
Creates a lazy iterable of the leading elements satisfying test.
The filtering happens lazily. Every new iterator of the returned iterable starts iterating over the elements of this.
The elements can be computed by stepping through iterator until an element is found where test(element) is false. At that point, the returned iterable stops (its moveNext() returns false).
Example:
dart
final numbers = <int>[1, 2, 3, 5, 6, 7];
var result = numbers.takeWhile((x) => x < 5); // (1, 2, 3)
result = numbers.takeWhile((x) => x != 3); // (1, 2)
result = numbers.takeWhile((x) => x != 4); // (1, 2, 3, 5, 6, 7)
result = numbers.takeWhile((x) => x.isOdd); // (1)Inherited from Iterable.
Implementation
dart
Iterable<E> takeWhile(bool test(E value)) => TakeWhileIterable<E>(this, test);toList() inherited
Creates a List containing the elements of this Iterable.
The elements are in iteration order. The list is fixed-length if growable is false.
Example:
dart
final planets = <int, String>{1: 'Mercury', 2: 'Venus', 3: 'Mars'};
final keysList = planets.keys.toList(growable: false); // [1, 2, 3]
final valuesList =
planets.values.toList(growable: false); // [Mercury, Venus, Mars]Inherited from Iterable.
Implementation
dart
List<E> toList({bool growable = true}) =>
List<E>.of(this, growable: growable);toSet() inherited
Set<E> toSet()Creates a Set containing the same elements as this iterable.
The set may contain fewer elements than the iterable, if the iterable contains an element more than once, or it contains one or more elements that are equal. The order of the elements in the set is not guaranteed to be the same as for the iterable.
Example:
dart
final planets = <int, String>{1: 'Mercury', 2: 'Venus', 3: 'Mars'};
final valueSet = planets.values.toSet(); // {Mercury, Venus, Mars}Inherited from Iterable.
Implementation
dart
Set<E> toSet() => Set<E>.of(this);toString() inherited
String toString()Returns a string representation of (some of) the elements of this.
Elements are represented by their own toString results.
The default representation always contains the first three elements. If there are less than a hundred elements in the iterable, it also contains the last two elements.
If the resulting string isn't above 80 characters, more elements are included from the start of the iterable.
The conversion may omit calling toString on some elements if they are known to not occur in the output, and it may stop iterating after a hundred elements.
Inherited from Iterable.
Implementation
dart
String toString() => iterableToShortString(this, '(', ')');where() inherited
Creates a new lazy Iterable with all elements that satisfy the predicate test.
The matching elements have the same order in the returned iterable as they have in iterator.
This method returns a view of the mapped elements. As long as the returned Iterable is not iterated over, the supplied function test will not be invoked. Iterating will not cache results, and thus iterating multiple times over the returned Iterable may invoke the supplied function test multiple times on the same element.
Example:
dart
final numbers = <int>[1, 2, 3, 5, 6, 7];
var result = numbers.where((x) => x < 5); // (1, 2, 3)
result = numbers.where((x) => x > 5); // (6, 7)
result = numbers.where((x) => x.isEven); // (2, 6)Inherited from Iterable.
Implementation
dart
Iterable<E> where(bool test(E element)) => WhereIterable<E>(this, test);whereType() inherited
Iterable<T> whereType<T>()Creates a new lazy Iterable with all elements that have type T.
The matching elements have the same order in the returned iterable as they have in iterator.
This method returns a view of the mapped elements. Iterating will not cache results, and thus iterating multiple times over the returned Iterable may yield different results, if the underlying elements change between iterations.
Inherited from Iterable.
Implementation
dart
Iterable<T> whereType<T>() => WhereTypeIterable<T>(this);Operators
operator ==() inherited
The equality operator.
The default behavior for all Objects is to return true if and only if this object and other are the same object.
Override this method to specify a different equality relation on a class. The overriding method must still be an equivalence relation. That is, it must be:
Total: It must return a boolean for all arguments. It should never throw.
Reflexive: For all objects
o,o == omust be true.Symmetric: For all objects
o1ando2,o1 == o2ando2 == o1must either both be true, or both be false.Transitive: For all objects
o1,o2, ando3, ifo1 == o2ando2 == o3are true, theno1 == o3must be true.
The method should also be consistent over time, so whether two objects are equal should only change if at least one of the objects was modified.
If a subclass overrides the equality operator, it should override the hashCode method as well to maintain consistency.
Inherited from Object.
Implementation
dart
external bool operator ==(Object other);