Capturing with Match

Previously, we did two different things with fields during a match expression:

  • Matched on them, e.g., Teacher(Art)

  • Used a wild card and ignored them, e.g., Teacher(_)

There’s another highly useful thing you can do, capture the field’s value in a variable. Then you can use that variable inside the expression. It’s easiest to see this in an example. So, behold my power levels!