title: How to extract Left or Right easily from Either type in Dart (Dartz)
body: <p>I am looking to extract a value easily from a method that return a type <code>Either&lt;Exception, Object&gt;</code>. </p>
  
  <p>I am doing some tests but unable to test easily the return of my methods.</p>
  
  <p><strong>For example:</strong> </p>
  
  <pre><code>final Either&lt;ServerException, TokenModel&gt; result = await repository.getToken(...);
  </code></pre>
  
  <p>To test I am able to do that</p>
  
  <pre><code>expect(result, equals(Right(tokenModelExpected))); // =&gt; OK
  </code></pre>
  
  <p>Now how can I retrieve the result directly?</p>
  
  <pre><code>final TokenModel modelRetrieved = Left(result); ==&gt; Not working..
  </code></pre>
  
  <p>I found that I have to cast like that:</p>
  
  <pre><code>final TokenModel modelRetrieved = (result as Left).value; ==&gt; But I have some linter complain, that telling me that I shouldn't do as to cast on object...
  </code></pre>
  
  <p>Also I would like to test the exception but it's not working, for example:</p>
  
  <pre><code>expect(result, equals(Left(ServerException()))); // =&gt; KO
  </code></pre>
  
  <p>So I tried this </p>
  
  <pre><code>expect(Left(ServerException()), equals(Left(ServerException()))); // =&gt; KO as well, because it says that the instances are different.
  </code></pre>