toCollection<C extends KtMutableCollection> method

C toCollection<C extends KtMutableCollection>(
  1. C destination
)

Appends all elements to the given destination collection.

destination is not type checked by the compiler due to https://github.com/dart-lang/sdk/issues/35518, but will be checked at runtime. M actually is expected to be M extends KtMutableCollection<T>

Implementation

// TODO Change to `M extends KtMutableCollection<T>` once https://github.com/dart-lang/sdk/issues/35518 has been fixed
C toCollection<C extends KtMutableCollection<dynamic>>(C destination) {
  assert(() {
    if (mutableListOf<T>() is! C) {
      throw ArgumentError(
          "toCollection destination has wrong type parameters."
          "\nExpected: KtMutableCollection<$T>, Actual: ${destination.runtimeType}"
          "\ndestination (${destination.runtimeType}) entries aren't subtype of "
          "map ($runtimeType) entries. Entries can't be copied to destination."
          "\n\n$kBug35518GenericTypeError");
    }
    return true;
  }());
  for (final item in iter) {
    destination.add(item);
  }
  return destination;
}