# toMap<K, V> method

Map<K, V> toMap<K, V>(

1. K keySelector(
   1. T item
   ),
2. V valueSelector(
   1. T item
   )

)

Maps the iterable to a new iterable using the provided `mapper` function.

## Parameters

- `mapper`: The function to apply to each element of the iterable

## Returns

- A new iterable containing the mapped elements

## Example

    final fruits = ["apple", "banana", "cherry"];

    final fruitLengthMap = fruits.toMap(
      (fruit) => fruit,        // key = the fruit itself
      (fruit) => fruit.length, // value = length of the fruit
    );
    print(fruitLengthMap); // {apple: 5, banana: 6, cherry: 6}

## Implementation

    //
    /// print(fruitLengthMap); // {apple: 5, banana: 6, cherry: 6}
    /// ```
    Map<K, V> toMap<K, V>(K Function(T item) keySelector, V Function(T item) valueSelector) {
      final Map<K, V> result = {};
      for (final element in this) {
        final key = keySelector(element);
        result.putIfAbsent(key, () => valueSelector(element));
      }

      return result;
    }