Skip to content
kshalle edited this page Apr 15, 2018 · 1 revision

A good explanation of match operator is in the Chisel tutorial

Here, we give some more advanced examples and walk through the details of what's going on.

val root = res match { //res is passed in, then we compare "case" values to it, and result of match is returned
      case ResourceMap(value, _) => value.toList match { //ResourceMap defined in diplomacy/Resources.scala
        case Seq(("/", Seq(subtree))) => subtree //"Seq" creates a list, to which the case checks for a match
        case _ => res
      }
      case _ => res
    }

The tricky parts are the use of ResourceMap and the embedded second level of match.

The ResourceMap is defined in diplomacy/Resources.scala as:

final case class ResourceMap(value: Map[String, Seq[ResourceValue]], labels: Seq[String] = Nil) extends ResourceValue

It's use results in embedded match takes the result of the ResourceMap as an input.. and the result of the second match is actually the valu

Clone this wiki locally