title: using the Maybe monad with monadic actions
body: <p>When I have for instance a <code>Maybe</code> value, and I want to apply something on it when it's a <code>Just</code> or just keep a <code>Nothing</code> if it was a <code>Nothing</code>, I have many ways to achieve that in haskell. However I did not find a concise way when I want to apply on it a monadic action.</p>
  
  <p>In this code, to get <code>d</code> I can just use <code>fmap</code>. But I can't use it to get <code>c</code> because that one requires a monadic (<code>IO</code> in this case) action to apply on the value in the <code>Maybe</code>.</p>
  
  <pre><code>import Control.Applicative
  
  main = do
      let x = Just "test.txt"
      let d = reverse &lt;$&gt; x -- good
      print d
      c &lt;- case x of -- verbose
       Nothing -&gt; return Nothing
       Just y -&gt; Just &lt;$&gt; readFile y
      print c
  </code></pre>
  
  <p>This is a way it can be done, but it's also too verbose.</p>
  
  <pre><code>    c' &lt;- maybe (return Nothing) (\a -&gt; Just &lt;$&gt; readFile a) x
      print c'
  </code></pre>
  
  <p>I'm sure there's a shorter way, I just can't see it right now...</p>