| Index: sdk/lib/internal/iterable.dart
|
| diff --git a/sdk/lib/internal/iterable.dart b/sdk/lib/internal/iterable.dart
|
| index 87c5f141b32787219504f5a54b413e9dc6596c3c..bc80b88ba40caf4387c6415ebe2da4c2af580edd 100644
|
| --- a/sdk/lib/internal/iterable.dart
|
| +++ b/sdk/lib/internal/iterable.dart
|
| @@ -757,404 +757,6 @@ abstract class BidirectionalIterator<T> implements Iterator<T> {
|
| bool movePrevious();
|
| }
|
|
|
| -/**
|
| - * This class provides default implementations for Iterables (including Lists).
|
| - *
|
| - * The uses of this class will be replaced by mixins.
|
| - */
|
| -class IterableMixinWorkaround<T> {
|
| - static bool contains(Iterable iterable, var element) {
|
| - for (final e in iterable) {
|
| - if (e == element) return true;
|
| - }
|
| - return false;
|
| - }
|
| -
|
| - static void forEach(Iterable iterable, void f(o)) {
|
| - for (final e in iterable) {
|
| - f(e);
|
| - }
|
| - }
|
| -
|
| - static bool any(Iterable iterable, bool f(o)) {
|
| - for (final e in iterable) {
|
| - if (f(e)) return true;
|
| - }
|
| - return false;
|
| - }
|
| -
|
| - static bool every(Iterable iterable, bool f(o)) {
|
| - for (final e in iterable) {
|
| - if (!f(e)) return false;
|
| - }
|
| - return true;
|
| - }
|
| -
|
| - static dynamic reduce(Iterable iterable,
|
| - dynamic combine(previousValue, element)) {
|
| - Iterator iterator = iterable.iterator;
|
| - if (!iterator.moveNext()) throw IterableElementError.noElement();
|
| - var value = iterator.current;
|
| - while (iterator.moveNext()) {
|
| - value = combine(value, iterator.current);
|
| - }
|
| - return value;
|
| - }
|
| -
|
| - static dynamic fold(Iterable iterable,
|
| - dynamic initialValue,
|
| - dynamic combine(dynamic previousValue, element)) {
|
| - for (final element in iterable) {
|
| - initialValue = combine(initialValue, element);
|
| - }
|
| - return initialValue;
|
| - }
|
| -
|
| - /**
|
| - * Removes elements matching [test] from [list].
|
| - *
|
| - * This is performed in two steps, to avoid exposing an inconsistent state
|
| - * to the [test] function. First the elements to retain are found, and then
|
| - * the original list is updated to contain those elements.
|
| - */
|
| - static void removeWhereList(List list, bool test(var element)) {
|
| - List retained = [];
|
| - int length = list.length;
|
| - for (int i = 0; i < length; i++) {
|
| - var element = list[i];
|
| - if (!test(element)) {
|
| - retained.add(element);
|
| - }
|
| - if (length != list.length) {
|
| - throw new ConcurrentModificationError(list);
|
| - }
|
| - }
|
| - if (retained.length == length) return;
|
| - list.length = retained.length;
|
| - for (int i = 0; i < retained.length; i++) {
|
| - list[i] = retained[i];
|
| - }
|
| - }
|
| -
|
| - static bool isEmpty(Iterable iterable) {
|
| - return !iterable.iterator.moveNext();
|
| - }
|
| -
|
| - static dynamic first(Iterable iterable) {
|
| - Iterator it = iterable.iterator;
|
| - if (!it.moveNext()) {
|
| - throw IterableElementError.noElement();
|
| - }
|
| - return it.current;
|
| - }
|
| -
|
| - static dynamic last(Iterable iterable) {
|
| - Iterator it = iterable.iterator;
|
| - if (!it.moveNext()) {
|
| - throw IterableElementError.noElement();
|
| - }
|
| - dynamic result;
|
| - do {
|
| - result = it.current;
|
| - } while(it.moveNext());
|
| - return result;
|
| - }
|
| -
|
| - static dynamic single(Iterable iterable) {
|
| - Iterator it = iterable.iterator;
|
| - if (!it.moveNext()) throw IterableElementError.noElement();
|
| - dynamic result = it.current;
|
| - if (it.moveNext()) throw IterableElementError.tooMany();
|
| - return result;
|
| - }
|
| -
|
| - static dynamic firstWhere(Iterable iterable,
|
| - bool test(dynamic value),
|
| - dynamic orElse()) {
|
| - for (dynamic element in iterable) {
|
| - if (test(element)) return element;
|
| - }
|
| - if (orElse != null) return orElse();
|
| - throw IterableElementError.noElement();
|
| - }
|
| -
|
| - static dynamic lastWhere(Iterable iterable,
|
| - bool test(dynamic value),
|
| - dynamic orElse()) {
|
| - dynamic result = null;
|
| - bool foundMatching = false;
|
| - for (dynamic element in iterable) {
|
| - if (test(element)) {
|
| - result = element;
|
| - foundMatching = true;
|
| - }
|
| - }
|
| - if (foundMatching) return result;
|
| - if (orElse != null) return orElse();
|
| - throw IterableElementError.noElement();
|
| - }
|
| -
|
| - static dynamic lastWhereList(List list,
|
| - bool test(dynamic value),
|
| - dynamic orElse()) {
|
| - // TODO(floitsch): check that arguments are of correct type?
|
| - for (int i = list.length - 1; i >= 0; i--) {
|
| - dynamic element = list[i];
|
| - if (test(element)) return element;
|
| - }
|
| - if (orElse != null) return orElse();
|
| - throw IterableElementError.noElement();
|
| - }
|
| -
|
| - static dynamic singleWhere(Iterable iterable, bool test(dynamic value)) {
|
| - dynamic result = null;
|
| - bool foundMatching = false;
|
| - for (dynamic element in iterable) {
|
| - if (test(element)) {
|
| - if (foundMatching) {
|
| - throw IterableElementError.tooMany();
|
| - }
|
| - result = element;
|
| - foundMatching = true;
|
| - }
|
| - }
|
| - if (foundMatching) return result;
|
| - throw IterableElementError.noElement();
|
| - }
|
| -
|
| - static elementAt(Iterable iterable, int index) {
|
| - if (index is! int) throw new ArgumentError.notNull("index");
|
| - RangeError.checkNotNegative(index, "index");
|
| - int elementIndex = 0;
|
| - for (var element in iterable) {
|
| - if (index == elementIndex) return element;
|
| - elementIndex++;
|
| - }
|
| - throw new RangeError.index(index, iterable, "index", null, elementIndex);
|
| - }
|
| -
|
| - static String join(Iterable iterable, [String separator]) {
|
| - StringBuffer buffer = new StringBuffer();
|
| - buffer.writeAll(iterable, separator);
|
| - return buffer.toString();
|
| - }
|
| -
|
| - static String joinList(List list, [String separator]) {
|
| - if (list.isEmpty) return "";
|
| - if (list.length == 1) return "${list[0]}";
|
| - StringBuffer buffer = new StringBuffer();
|
| - if (separator.isEmpty) {
|
| - for (int i = 0; i < list.length; i++) {
|
| - buffer.write(list[i]);
|
| - }
|
| - } else {
|
| - buffer.write(list[0]);
|
| - for (int i = 1; i < list.length; i++) {
|
| - buffer.write(separator);
|
| - buffer.write(list[i]);
|
| - }
|
| - }
|
| - return buffer.toString();
|
| - }
|
| -
|
| - Iterable<T> where(Iterable iterable, bool f(var element)) {
|
| - return new WhereIterable<T>(iterable, f);
|
| - }
|
| -
|
| - static Iterable map(Iterable iterable, f(var element)) {
|
| - return new MappedIterable(iterable, f);
|
| - }
|
| -
|
| - static Iterable mapList(List list, f(var element)) {
|
| - return new MappedListIterable(list, f);
|
| - }
|
| -
|
| - static Iterable expand(Iterable iterable, Iterable f(var element)) {
|
| - return new ExpandIterable(iterable, f);
|
| - }
|
| -
|
| - Iterable<T> takeList(List list, int n) {
|
| - // The generic type is currently lost. It will be fixed with mixins.
|
| - return new SubListIterable<T>(list, 0, n);
|
| - }
|
| -
|
| - Iterable<T> takeWhile(Iterable iterable, bool test(var value)) {
|
| - // The generic type is currently lost. It will be fixed with mixins.
|
| - return new TakeWhileIterable<T>(iterable, test);
|
| - }
|
| -
|
| - Iterable<T> skipList(List list, int n) {
|
| - // The generic type is currently lost. It will be fixed with mixins.
|
| - return new SubListIterable<T>(list, n, null);
|
| - }
|
| -
|
| - Iterable<T> skipWhile(Iterable iterable, bool test(var value)) {
|
| - // The generic type is currently lost. It will be fixed with mixins.
|
| - return new SkipWhileIterable<T>(iterable, test);
|
| - }
|
| -
|
| - Iterable<T> reversedList(List list) {
|
| - return new ReversedListIterable<T>(list);
|
| - }
|
| -
|
| - static void sortList(List list, int compare(a, b)) {
|
| - if (compare == null) compare = Comparable.compare;
|
| - Sort.sort(list, compare);
|
| - }
|
| -
|
| - static void shuffleList(List list, Random random) {
|
| - if (random == null) random = new Random();
|
| - int length = list.length;
|
| - while (length > 1) {
|
| - int pos = random.nextInt(length);
|
| - length -= 1;
|
| - var tmp = list[length];
|
| - list[length] = list[pos];
|
| - list[pos] = tmp;
|
| - }
|
| - }
|
| -
|
| - static int indexOfList(List list, var element, int start) {
|
| - return Lists.indexOf(list, element, start, list.length);
|
| - }
|
| -
|
| - static int lastIndexOfList(List list, var element, int start) {
|
| - if (start == null) start = list.length - 1;
|
| - return Lists.lastIndexOf(list, element, start);
|
| - }
|
| -
|
| - static void _rangeCheck(List list, int start, int end) {
|
| - RangeError.checkValidRange(start, end, list.length);
|
| - }
|
| -
|
| - Iterable<T> getRangeList(List list, int start, int end) {
|
| - _rangeCheck(list, start, end);
|
| - // The generic type is currently lost. It will be fixed with mixins.
|
| - return new SubListIterable<T>(list, start, end);
|
| - }
|
| -
|
| - static void setRangeList(List list, int start, int end,
|
| - Iterable from, int skipCount) {
|
| - _rangeCheck(list, start, end);
|
| - int length = end - start;
|
| - if (length == 0) return;
|
| -
|
| - if (skipCount < 0) throw new ArgumentError(skipCount);
|
| -
|
| - // TODO(floitsch): Make this accept more.
|
| - List otherList;
|
| - int otherStart;
|
| - if (from is List) {
|
| - otherList = from;
|
| - otherStart = skipCount;
|
| - } else {
|
| - otherList = from.skip(skipCount).toList(growable: false);
|
| - otherStart = 0;
|
| - }
|
| - if (otherStart + length > otherList.length) {
|
| - throw IterableElementError.tooFew();
|
| - }
|
| - Lists.copy(otherList, otherStart, list, start, length);
|
| - }
|
| -
|
| - static void replaceRangeList(List list, int start, int end,
|
| - Iterable iterable) {
|
| - _rangeCheck(list, start, end);
|
| - if (iterable is! EfficientLength) {
|
| - iterable = iterable.toList();
|
| - }
|
| - int removeLength = end - start;
|
| - int insertLength = iterable.length;
|
| - if (removeLength >= insertLength) {
|
| - int delta = removeLength - insertLength;
|
| - int insertEnd = start + insertLength;
|
| - int newEnd = list.length - delta;
|
| - list.setRange(start, insertEnd, iterable);
|
| - if (delta != 0) {
|
| - list.setRange(insertEnd, newEnd, list, end);
|
| - list.length = newEnd;
|
| - }
|
| - } else {
|
| - int delta = insertLength - removeLength;
|
| - int newLength = list.length + delta;
|
| - int insertEnd = start + insertLength; // aka. end + delta.
|
| - list.length = newLength;
|
| - list.setRange(insertEnd, newLength, list, end);
|
| - list.setRange(start, insertEnd, iterable);
|
| - }
|
| - }
|
| -
|
| - static void fillRangeList(List list, int start, int end, fillValue) {
|
| - _rangeCheck(list, start, end);
|
| - for (int i = start; i < end; i++) {
|
| - list[i] = fillValue;
|
| - }
|
| - }
|
| -
|
| - static void insertAllList(List list, int index, Iterable iterable) {
|
| - RangeError.checkValueInInterval(index, 0, list.length, "index");
|
| - if (iterable is! EfficientLength) {
|
| - iterable = iterable.toList(growable: false);
|
| - }
|
| - int insertionLength = iterable.length;
|
| - list.length += insertionLength;
|
| - list.setRange(index + insertionLength, list.length, list, index);
|
| - for (var element in iterable) {
|
| - list[index++] = element;
|
| - }
|
| - }
|
| -
|
| - static void setAllList(List list, int index, Iterable iterable) {
|
| - RangeError.checkValueInInterval(index, 0, list.length, "index");
|
| - for (var element in iterable) {
|
| - list[index++] = element;
|
| - }
|
| - }
|
| -
|
| - Map<int, T> asMapList(List l) {
|
| - return new ListMapView<T>(l);
|
| - }
|
| -
|
| - static bool setContainsAll(Set set, Iterable other) {
|
| - for (var element in other) {
|
| - if (!set.contains(element)) return false;
|
| - }
|
| - return true;
|
| - }
|
| -
|
| - static Set setIntersection(Set set, Set other, Set result) {
|
| - Set smaller;
|
| - Set larger;
|
| - if (set.length < other.length) {
|
| - smaller = set;
|
| - larger = other;
|
| - } else {
|
| - smaller = other;
|
| - larger = set;
|
| - }
|
| - for (var element in smaller) {
|
| - if (larger.contains(element)) {
|
| - result.add(element);
|
| - }
|
| - }
|
| - return result;
|
| - }
|
| -
|
| - static Set setUnion(Set set, Set other, Set result) {
|
| - result.addAll(set);
|
| - result.addAll(other);
|
| - return result;
|
| - }
|
| -
|
| - static Set setDifference(Set set, Set other, Set result) {
|
| - for (var element in set) {
|
| - if (!other.contains(element)) {
|
| - result.add(element);
|
| - }
|
| - }
|
| - return result;
|
| - }
|
| -}
|
|
|
| /**
|
| * Creates errors throw by [Iterable] when the element count is wrong.
|
|
|