title: Scala pipe patternmatching as a variable
body: <p>Often it is required to execute the same code for multiple values. With match this can be done using | (pipe) operator:</p>
  <pre class="lang-scala prettyprint-override"><code>val state = &quot;stopped&quot;
  val value = 0
  (state, value) match {
      case (&quot;running&quot; | &quot;pending&quot;, 0)   =&gt; println(&quot;running with no value&quot;)
      case (&quot;stopped&quot; | &quot;cancelled&quot;, 0) =&gt; println(&quot;not running; no value&quot;)
      case (&quot;running&quot; | &quot;pending&quot;, _)   =&gt; println(&quot;running with a value&quot;)
      case (&quot;stopped&quot; | &quot;cancelled&quot;, _) =&gt; println(&quot;not running with a value&quot;)
      case _                            =&gt; println(&quot;unknown state&quot;)
  }
  </code></pre>
  <p>Is there a method to write the pipes as a variable, eg:</p>
  <pre class="lang-scala prettyprint-override"><code>val runningStates    = &quot;running&quot; | &quot;pending&quot;
  val nonRunningStates = &quot;stopped&quot; | &quot;cancelled&quot;
  </code></pre>
  <p>So I can use these in the above pattern matching:</p>
  <pre class="lang-scala prettyprint-override"><code>(state, value) match {
      case (runningStates, 0)    =&gt; println(&quot;running with no value&quot;)
      case (nonRunningStates, 0) =&gt; println(&quot;not running; no value&quot;)
      case (runningStates, _)    =&gt; println(&quot;running with a value&quot;)
      case (nonRunningStates, _) =&gt; println(&quot;not running with a value&quot;)
      case _                     =&gt; println(&quot;unknown state&quot;)
  }
  </code></pre>