mapTo<R, M extends KtMutableCollection> method Null safety

M mapTo<R, M extends KtMutableCollection>(
  1. M destination,
  2. R transform(
    1. KtMapEntry<K, V> entry

Applies the given transform function to each entry of the original map and appends the results to the given destination.


// TODO Change to `M extends KtMutableCollection<R>` once has been fixed
M mapTo<R, M extends KtMutableCollection<dynamic>>(
    M destination, R Function(KtMapEntry<K, V> entry) transform) {
  assert(() {
    if (destination is! KtMutableCollection<R> &&
        mutableListFrom<R>() is! M) {
      throw ArgumentError("mapTo destination has wrong type parameters."
          "\nExpected: KtMutableCollection<$R>, Actual: ${destination.runtimeType}"
          "\nEntries after key transformation with $transform have type $R "
          "and can't be copied into destination of type ${destination.runtimeType}."
    return true;
  for (final item in iter) {
  return destination;