I have a protocol that has typealias:
protocol Fooable {
typealias T: Equatable
func makeFoo() -> T
}
I expect all types matching it to return equal values from makeFoo.
Now, I would like to create an array extension in which the values are stored Fooable:
extension Array where Element: Fooable {
func arrayFoo<F: Foobable, S>(array: Array<F>, transform: (Element, [F]) -> S) -> [S] {
I expect that given array A containing elements Fooableand array B which contains elements Fooable, I can do:
a.arrayFoo(b, {...})
I have a function part arrayFoo:
var leftGenerator = self.generate()
var rightGenerator = array.generate()
if let leftValue = leftGenerator.next(), rightValue = rightGenerator.next() {
let leftFoo = leftValue.makeFoo()
let rightFoo = rightValue.makeFoo()
if leftFoo == rightFoo {
I expect that leftFoothey rightFoowill be Equableable, because they are created with the help makeFoo()that Equatables should return.
But Swift complains: Binary operator == cannot be applied to operands of type Element.T and F.T
Any ideas or workarounds?
source
share