Hacker News new | ask | show | jobs
by fhars 4566 days ago
No, your first sentence is wrong. The following definition stores the ranks as unboxed integers, but prints them differently:

    case class Rank private (val rank : Int) extends AnyVal {
      override def toString() = {
        rank match {
          case 1 => "A" 
          case 11 => "J"
          case 12 => "Q"
          case 13 => "K"
          case _ => rank.toString()
        }
      }
    }   

    object Rank {
       val Ace = Rank(1)
       val Two = Rank(2)
       // ...
       val King = Rank(13)
    }
1 comments

And you can create a new string interpolation to make card instances, like:

    card"Heart:Ace"
or

    card"$suite:Ace" if you want to reference a variable.