Skip to content

Instantly share code, notes, and snippets.

/contins.swift
Created Jan 24, 2017

Embed
What would you like to do?
[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
You can’t perform that action at this time.