Avoid calling count
on a non-RandomAccess
collection, by leveraging the fact that a slice shares indices with its base collection:
return self[..<suffix.startIndex]
Or, using only standard library methods:
let i = try lastIndex{ try !predicate($0) }
guard let j = i else {
return self[..<startIndex]
}
return self[...j]