mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
17 lines
436 B
Swift
17 lines
436 B
Swift
// RUN: %target-swift-frontend -primary-file %s -emit-ir
|
|
|
|
// https://github.com/apple/swift/issues/47194
|
|
|
|
extension Dictionary {
|
|
init<S: Sequence>(grouping elements: S, by keyForValue: (S.Iterator.Element) -> Key)
|
|
where Array<S.Iterator.Element> == Value
|
|
{
|
|
self = [:]
|
|
for value in elements {
|
|
var values = self[keyForValue(value)] ?? []
|
|
values.append(value)
|
|
self[keyForValue(value)] = values
|
|
}
|
|
}
|
|
}
|