isContained(in array:) extension of Equatable

I agree with Pierpaolo's linguistic framing of the issue. I wrote a few months ago about the difference between Swift's collection.contains(element) and Python's element in collection.

To sum up, Swift likes to expose how methods are dispatched. The Swift community loves discussions about method dispatch. We're dispatching-obsessed. Hence collection.contains(element) instead of element.in(collection). That's because the language shows who decides of the actual implementation (the collection, not the element).

Now, I do lack some kind of in operator sometimes. Clear method dispatch is great, but code legibility would sometimes be enhanced with some reversed test.

4 Likes