Motivation: Trying to construct an 'contains' function that return true or false depending on if the array contains the parameter supplied in object.
Error: Can't invoke 'exist' with argument list of type '((T) -> Bool)'
I can't tell if the problem is in extension of Array,or 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}
}
}
Aucun commentaire:
Enregistrer un commentaire