Turn a record field into a readable label.

Matching a Field

FieldMatch.scala
case class Order(id: Int, status: Int)

object Main {
  def main(args: Array[String]): Unit = {
    val status = 
    val order = Order(7, status)
    val name = order.status match {
      case 0 => "new"
      case 1 => "paid"
      case 2 => "shipped"
      case _ => "unknown"
    }

    println("id=" + order.id)
    println("status=" + name)
  }
}
case class Order(id: Int, status: Int)

object Main {
  def main(args: Array[String]): Unit = {
    val status = 
    val order = Order(7, status)
    val name = order.status match {
      case 0 => "new"
      case 1 => "paid"
      case 2 => "shipped"
      case _ => "unknown"
    }

    println("id=" + order.id)
    println("status=" + name)
  }
}
case class Order(id: Int, status: Int)

object Main {
  def main(args: Array[String]): Unit = {
    val status = 
    val order = Order(7, status)
    val name = order.status match {
      case 0 => "new"
      case 1 => "paid"
      case 2 => "shipped"
      case _ => "unknown"
    }

    println("id=" + order.id)
    println("status=" + name)
  }
}
field-match A `match` can run on a single field of a case class. Each status code maps to a label, and the `_` case covers any value that is not listed.