toMap<K, V> method

Map<K, V> toMap<K, V>(
  1. Pair<K, V>? collector(
    1. T element
    )
)

Converts the list to Map. Use collector to convert each element to a key-value Pair, which represents a map entry.

Implementation

Map<K, V> toMap<K, V>(Pair<K, V>? Function(T element) collector) {
  final resultMap = <K, V>{};

  for (final element in this) {
    final pair = collector(element);
    if (pair != null) {
      resultMap[pair.key] = pair.value;
    }
  }

  return resultMap;
}