Segmentation fault 11 for function naming in protocol extension

81 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 answers

0
Richard Birkett 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?