Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In case classes constructor arguments are vals, so just call:</p> <pre><code>a.input b.input </code></pre> <p>You can also use extractor with the help of <code>unapply</code> method:</p> <pre><code>val Foo(val1) = a val Bar(val2) = b </code></pre> <p>and then use <code>val1</code> and <code>val2</code></p> <p><strong>Update</strong></p> <p>Then you should use pattern matching on your value:</p> <pre><code>value match { case Foo(val1) =&gt; val1 case Bar(val1) =&gt; val1 } </code></pre> <p>It works just like <code>val Foo(val1) = a</code>, with using generated <code>unapply</code> method (extractor) in your class, and it is also an expression, so you van assign the result to the variable</p> <p>If you have multiple arguments just change PatMat construct according to the number of your parameters, in your case:</p> <pre><code>someMethod(a: Something, b: Something) = (a, b) match { case (Foo(v1), Foo(v2)) =&gt; (v1, v2) // or any other logic with values case (Foo(v1), Bar(v2)) =&gt; // logic for this case ... // logic for other cases } </code></pre> <p>The more parameters the more cases you should provide, but you case blank cases if you don't need them</p> <pre><code>someMethod(a: Something, b: Something) = (a, b) match { case (Foo(v1), Foo(v2)) =&gt; (v1, v2) // or any other logic with values case _ =&gt; } </code></pre> <p>in this case all other cases will be ignored, not the best choice, cause the result type will be incorrect. And you also can black values</p> <pre><code>someMethod(a: Something, b: Something) = (a, b) match { case (Foo(v1), _) =&gt; v1 // in such case you can work only with v1 ... // logic for other cases } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload