Using ... as a concrete type conforming to protocol ... is not supported


(Jason Sadler) #1

It turns out you can use an equality type constraint instead of a conformance type constraint:

extension CollectionType where Generator.Element == AnyEquatable {
    func indexOf(element : AnyEquatable) -> Index? {
        return indexOf({ (currentElement : Generator.Element ) -> Bool in
            element.equals(currentElement)
        })
    }
}

Discussion is ongoing at swift-evolution: https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160328/013922.html