keyed(by:resolvingConflictsWith:)

Creates a new Dictionary from the elements of self, keyed by the results returned by the given keyForValue closure. As the dictionary is built, the initializer calls the resolve closure with the current and new values for any duplicate keys. Pass a closure as resolve that returns the value to use in the resulting dictionary: The closure can choose between the two values, combine them to produce a new value, or even throw an error.

Keyed.swift:42
func keyed<Key>(by keyForValue: (Element) throws -> Key, resolvingConflictsWith resolve: (Key, Element, Element) throws -> Element) rethrows -> [Key : Element] where Key : Hashable

Parameters

keyForValue

A closure that returns a key for each element in self.

resolve

A closure that is called with the values for any duplicate keys that are encountered. The closure returns the desired value for the final dictionary.