Recently, I have been reading "functional programming in fast." In the book, the author makes some Int extension to conform to the protocol Smaller. To get a complete picture of the idea of the author, I copy the code to my own site, but it reports an error.
protocol Smaller {
static func smaller() -> Self?
}
extension Int: Smaller {
static func smaller() -> Int? {
return self == 0 ? nil : self / 2
}
}
It seems that it is self == 0not allowed in the extension. Does anyone have an idea of the reason.
source
share