title: How to filter based on monadic pattern match?
body: <p>I have the following problem:</p>
  
  <p>Given a type <code>data T = T (Maybe Int)</code>, how can I filter  a list getting the non-<code>Nothing</code> values?</p>
  
  <p><strong>Input</strong></p>
  
  <pre><code>a = [T (Just 3), T Nothing, T (Just 4)]
  </code></pre>
  
  <p><strong>Desired Output</strong></p>
  
  <pre><code>b = [T (Just 3), T (Just 4)]
  </code></pre>
  
  <p>I have tried something like :</p>
  
  <pre><code>b = filter (\x-&gt; x@(Just t)) a 
  </code></pre>
  
  <p>...thinking that I can filter based on a pattern match but i get the error:</p>
  
  <pre><code>Pattern syntax in expression context: x@(Just t)
      Did you mean to enable TypeApplications?
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/52315431/how-to-filter-based-on-monadic-pattern-match#comment91578571_52315450">I want to</a> later on be able to unpack the inner value (under <code>Just</code>) and use it accordingly. </p>