Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.

  class TinyInt(val int: Byte) {
    import TinyInt._
    require(int >= lower && int <= upper, "TinyInt out of bounds.")
 
    override def toString = int.toString
  }
 
  object TinyInt {
    val (lower, upper) = (1, 10)
 
    def apply(i: Byte) = new TinyInt(i)
  }
 
  val test = (TinyInt.lower to TinyInt.upper).map(n => TinyInt(n.toByte))