Xcode Version 8.0 (8A218a); Playground; Swift 3;
sample1: initial code
func fooA<C: Collection>(_ x: C)
where C.Iterator.Element == UInt8, C.IndexDistance == Int
{
let a = x.prefix(10).first(where: {$0 == 0xbf})
// ^^^^ ##ERROR##: Ambiguous reference to member `prefix`
print(a)
}
sample2: A few iterations later, trying to break expressions into simpler calls and removed inference.
func fooD<C: Collection>(_ x: C)
where C.Iterator.Element == UInt8, C.IndexDistance == Int
{
let x2: C.SubSequence = x.prefix(10)
let z: UInt8 = 0xbf
let a: UInt8? = x2.first(where: {
// ##ERROR##: Cannot convert value of type `(UInt8) -> Bool` to expected argument type `(_) -> Bool`
(a1: UInt8) -> Bool in
return a1 == z
})
print(a)
}
I don't understand where's the ambiguity in "sample2". I would greatly appreciate if someone could indicate where my failings. Thank you!