Segmentation fault 11 for function naming in protocol extension

96 Views Asked by At

The problem is really simple. This causes a segmentation fault:

extension Sequence {

    func parallelForEach<T, R>(_ f: @escaping (T) -> R, completion: @escaping ([R]) -> ()) where Iterator.Element == T {
    }

}

Clearly I don't know how to write a protocol extension anymore. Someone help please? :)

1

There are 1 best solutions below

0
On

The error was me thinking that I needed the generic type T. Since it was just Iterator.Element which is happily a type within the Sequence protocol.

extension Sequence {

    func parallelForEach<T, R>(_ f: @escaping (Iterator.Element) -> R, completion: @escaping ([R]) -> ()) {
    }

}

Kudos to anyone who can explain why the compiler didn't like it. It's clearly inefficient but why should it be wrong?