title: Is there (a -> b) -> ((Maybe a) -> (Maybe b)) converter in standard library?
body: <p>I'm just learning Haskell and I found myself writing this piece of code for homework assignment:</p>
  
  <pre><code>eval :: ExprT -&gt; Integer
  eval (Lit x)    = x
  eval (Add x y)  = (eval x) + (eval y)
  eval (Mul x y)  = (eval x) * (eval y)
  
  evalMayBe :: Maybe ExprT -&gt; Maybe Integer
  evalMayBe Nothing   = Nothing
  evalMayBe (Just x)  = Just (eval x)
  </code></pre>
  
  <p>The second function seemed a bit redundant, so I wrote a converter:</p>
  
  <pre><code>toMayBe :: (a -&gt; b) -&gt; Maybe a -&gt; Maybe b
  toMayBe _ Nothing   = Nothing
  toMayBe f (Just x)  = Just (f x)
  </code></pre>
  
  <p>And rewrote the function just as</p>
  
  <pre><code>evalMayBe :: Maybe ExprT -&gt; Maybe Integer
  evalMayBe = toMayBe eval
  </code></pre>
  
  <p>But then I thought that this converter seemed to be so useful for so many different situations that it must be in the standard library somewhere - however, I wasn't able to find it.</p>
  
  <p>Is it in the standard library? And what is the "right" way to write code like this, where you must chain a function on values in a chain where these values might be a Maybe?</p>