mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 16:00:45 +00:00
b9b6511ca6
Closes https://github.com/dart-lang/sdk/pull/50918 Co-authored-by: Josh Soref <jsoref@gmail.com> GitOrigin-RevId: 1fd275051c561b63d374fb47e76a22424c4a12a9 Change-Id: I97790d9c79ff659f2c1fa2d2d46d041fe67957cb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/278530 Reviewed-by: William Hesse <whesse@google.com> Commit-Queue: Alexander Thomas <athom@google.com> Reviewed-by: Tess Strickland <sstrickl@google.com>
27 lines
921 B
Dart
27 lines
921 B
Dart
/// Marker interface for [Iterable] subclasses that have an efficient
|
|
/// [length] implementation.
|
|
|
|
// @dart=2.9
|
|
|
|
abstract class EfficientLengthIterable<T> extends Iterable<T> {
|
|
const EfficientLengthIterable();
|
|
|
|
/// Returns the number of elements in the iterable.
|
|
///
|
|
/// This is an efficient operation that doesn't require iterating through
|
|
/// the elements.
|
|
int get length;
|
|
}
|
|
|
|
/// Creates errors throw by [Iterable] when the element count is wrong.
|
|
abstract class IterableElementError {
|
|
/// Error thrown by, e.g., [Iterable.first] when there is no result.
|
|
static StateError noElement() => StateError("No element");
|
|
|
|
/// Error thrown by, e.g., [Iterable.single] if there are too many results.
|
|
static StateError tooMany() => StateError("Too many elements");
|
|
|
|
/// Error thrown by, e.g., [List.setRange] if there are too few elements.
|
|
static StateError tooFew() => StateError("Too few elements");
|
|
}
|