I'm trying to construct a 'contains' function that return true or false depending on if the array contains the parameter supplied in object.
I get this error: Can't invoke 'exist' with argument list of type '((T) -> Bool)'
.
I can't tell if the problem is connected with the extension of Array, or it is in the closures.
Both expressions in contains()
have similar error.
The error looks ridiculous since ((T) -> Bool) is exactly what I have written for parameter of 'exist'
extension Array {
func exist(requirement:(T) -> Bool) -> Bool{
for a in self{
if(requirement(a)){
return true
}
}
return false
}
func contains(a:T) -> Bool {
//return exist{return $0==a}
return exist{(s0:T)->Bool in return s0==a}
}
}