Created
January 24, 2017 09:36
-
-
Save anonymous/171deb51bfb85f045b22e2b76157cae5 to your computer and use it in GitHub Desktop.
[Swift3] 集合(範囲)に含まれているかを確認する演算子
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
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