С этими определениями:
trait Inspector[-C, -T] {
def contains(collection: C, value: T): Boolean
}
implicit def seqInspector[T, C <: SeqLike[Any, _]] = new Inspector[C, T]{
override def contains(collection: C, value: T): Boolean = collection.contains(value)
}
implicit def setInspector[T, C <: Set[T]] = new Inspector[C, T] {
override def contains(collection: C, value: T): Boolean = collection.contains(value)
}
implicit class MemberOps[T](t: T) {
def in[C](coll: C)(implicit inspector: Inspector[C, T]) =
inspector.contains(coll, t)
}
Вы можете сделать такие проверки:
2 in List(1, 2, 4) // true
2 in List("foo", 2) // true
2 in Set("foo", 2) // true
2 in Set(1, 3) // false
2 in Set("foo", "foo") // does not compile
2 in List("foo", "foo") // false (contains on a list is not the same as contains on a set)
2 in (0 to 10) // true
Так что код, который вам нужен, будет:
val m = x in (0 to 10)