associate method
Creates a new Map by associating each element in the Iterable with a key-value pair.
The function takes a key parameter and a value parameter, both representing functions
that define the key and value for each element in the Iterable. It uses the fromIterable
constructor of the Map class to create a new Map by associating each element in the Iterable
with the key-value pair generated by the key and value functions.
Returns a new Map containing the associations between elements and key-value pairs.
Example:
List<String> names = ['Alice', 'Bob', 'Charlie'];
Map<String, int> nameLengths = names.associate((name) => name, (name) => name.length);
print(nameLengths); // Output: {Alice: 5, Bob: 3, Charlie: 7}
Implementation
Map<dynamic, dynamic> associate(key(element), value(element)) =>
Map.fromIterable(this, key: key, value: value);