mapTo<R, M extends KtMutableCollection> method

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.

Implementation

// TODO Change to `M extends KtMutableCollection<R>` once https://github.com/dart-lang/sdk/issues/35518 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}."
          "\n\n$kBug35518GenericTypeError");
    }
    return true;
  }());
  for (final item in iter) {
    destination.add(transform(item));
  }
  return destination;
}