Last active
January 20, 2019 23:15
-
-
Save LucianoPAlmeida/18160112445494db3aec851739e5a835 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct HTTPResponse { | |
var statusCode: Int | |
} | |
extension HTTPResponse { | |
func validateStatus<R>(in range: R) -> Bool where R: RangeExpression, R.Bound == Int { | |
return range~=self.statusCode | |
} | |
} | |
let http = HTTPResponse(statusCode: 200) | |
http.validateStatus(in: 200...) // PartialRangeFrom | |
http.validateStatus(in: 200...300) // ClosedRange | |
http.validateStatus(in: 200..<300) // Range | |
http.validateStatus(in: ...300) // PartialRangeThrough | |
http.validateStatus(in: ..<300) // PartialRangeUpTo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment