toMap<K, V> method

Map<K, V> toMap<K, V>(
  1. K keySelector(
    1. E e
    ),
  2. V valueTransform(
    1. E e
    )
)

Implementation

Map<K, V> toMap<K, V>(K keySelector(E e), V valueTransform(E e)) {
  Map<K, V> result = {};
  forEach((element) {
    K k = keySelector(element);
    if (result.containsKey(k)) {
      throw Exception("Key exist");
    }
    V v = valueTransform(element);
    result[k] = v;
  });
  return result;
}