Dictionary.keys should return a collection which can be equated without reference to order

Originator:saniul.ahmed
Number:rdar://23169050 Date Originated:19-Oct-2015 11:29 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode-beta (7B85)
Classification:Serious Bug Reproducible:Always
 
This is a duplicate of rdar://23166212

Summary:
When you have two dictionaries whose values are not equatable, but you have an equality function for them, one obvious way to compare them is to check that they have equal keys, and then check that for each key, the values from either dictionary are equal.

Like so:

	d1.keys == d2.keys && d1.keys.map { equal(d1[$0]!, d2[$0]!) }.reduce(true) { $0 && $1 }

However, you can’t do this—.keys returns a `LazyMapCollection<[Key:Value], Key>`, for which there is apparently no `==` function.

So what I did next was this:

	Array(d1.keys) == Array(d2.keys)

Now it compiles and all is well—except for the latent bug: dictionary key/value pair order is undefined, so the order of `keys` is undefined. What I wanted to do was:

	Set(d1.keys) == Set(d2.keys)

This is an avoidable bug. `keys` should return an unordered collection (whether a lazy one, a `Set`, or some `Set` analogue) that can be compared with a stdlib-defined `==` function (or better yet, a collection, like `Set`, which is actually Equatable).


Steps to Reproduce:
1. Check if there is a well-defined, ordering-insensitive `==` function in Swift’s stdlib for values returned from the `Dictionary.keys` property.


Expected Results:
There is.


Actual Results:
There is not.


Regression:
N/A

Notes:
N/A

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!