keyed(by:)

Creates a new Dictionary from the elements of self, keyed by the results returned by the given keyForValue closure.

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

Parameters

keyForValue

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

If the key derived for a new element collides with an existing key from a previous element, the latest value will be kept.