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.

struct SmallInt {
  var value: Int
 
  init(value: Int) {
    guard value >= 1 && value <= 10 else {
      fatalError("SmallInts must be in the range [1, 10]")
    }
 
    self.value = value
  }
 
  static func +(_ lhs: SmallInt, _ rhs: SmallInt) -> SmallInt { SmallInt(value: lhs.value + rhs.value) }
  static func -(_ lhs: SmallInt, _ rhs: SmallInt) -> SmallInt { SmallInt(value: lhs.value - rhs.value) }
  static func *(_ lhs: SmallInt, _ rhs: SmallInt) -> SmallInt { SmallInt(value: lhs.value * rhs.value) }
  static func /(_ lhs: SmallInt, _ rhs: SmallInt) -> SmallInt { SmallInt(value: lhs.value / rhs.value) }
}
 
extension SmallInt: ExpressibleByIntegerLiteral {
  public init(integerLiteral value: Int) { self.init(value: value) }
}
 
extension SmallInt: CustomStringConvertible {
  public var description: String { "\(value)" }
}
 
let a: SmallInt = 1
let b: SmallInt = 9
let c: SmallInt = 10
let d: SmallInt = 2
 
print(a + b)
print(c - b)
print(a * c)
print(c / d)
print(a + c)