Skip to content

Instantly share code, notes, and snippets.

@el-hoshino
Last active September 7, 2017 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save el-hoshino/7a5df71bbe8dc6adf1886714ba8a6e07 to your computer and use it in GitHub Desktop.
Save el-hoshino/7a5df71bbe8dc6adf1886714ba8a6e07 to your computer and use it in GitHub Desktop.
Swift 4 で「プラマイ」範囲を作る ref: http://qiita.com/lovee/items/4159b5c64b371ecb0b8f
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