Last active
September 7, 2017 06:52
-
-
Save el-hoshino/7a5df71bbe8dc6adf1886714ba8a6e07 to your computer and use it in GitHub Desktop.
Swift 4 で「プラマイ」範囲を作る ref: http://qiita.com/lovee/items/4159b5c64b371ecb0b8f
This file contains 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
infix operator ± : RangeFormationPrecedence | |
extension Numeric where Self: Comparable { | |
public static func ± (lhs: Self, rhs: Self) -> ClosedRange<Self> { | |
let added = lhs + rhs | |
let subtracted = lhs - rhs | |
let lowerBound = min(added, subtracted) | |
let upperBound = max(added, subtracted) | |
return lowerBound ... upperBound | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment