2 ms·
> Since Swift optionals are implemented using the Optional enum under the hood, we’re no longer able to perform the above kind of optional pattern matching on a
by saagarjha 7y ago
> Since Swift optionals are implemented using the Optional enum under the hood, we’re no longer able to perform the above kind of optional pattern matching on any enum that contains either a some or none case — since those will now conflict with the cases that Optional contains.
Wait, so if I wrote my own custom enum with .some and .none cases this will not work correctly? This seems like an overly broad scope; why can't the change have only affected Optional.some and Optional.none?
public extension Sequence where Element: Identifiable {
func keyedByID() -> [Element.ID : Element] {
var dictionary = [Element.ID : Element]()
forEach { dictionary[$0.id] = $0 }
return dictionary
}
}
Perhaps this could use Dictionary(grouping:by:)?