Skip to content

Instantly share code, notes, and snippets.

Created January 24, 2017 09:36
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 anonymous/171deb51bfb85f045b22e2b76157cae5 to your computer and use it in GitHub Desktop.
Save anonymous/171deb51bfb85f045b22e2b76157cae5 to your computer and use it in GitHub Desktop.
[Swift3] 集合(範囲)に含まれているかを確認する演算子
import Foundation
precedencegroup Group {
associativity: left
lowerThan: RangeFormationPrecedence
}
infix operator ⊂ : Group
func ⊂<T: Comparable> (value: T, pattern: CountableClosedRange<T> ) -> Bool {
return pattern ~= value
}
func ⊂<T: Comparable> (value: T, pattern: CountableRange<T> ) -> Bool {
return pattern ~= value
}
if 4 ⊂ 1...4 { print("hoge") } // true
if 4 ⊂ 1..<4 { print("???") } // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment