title: Map over list, except for last list element
body: <p>How do I best map over all elements of a list, except for the last list element?</p>
  
  <p>Say we have a list <code>let l = [1,2,3,4]</code> and want to get <code>[2,3,4,4]</code>. </p>
  
  <p>I do have a solution, but it doesn't feel like the "functional" way to do it (in ghci):</p>
  
  <pre><code>let l = [1,2,3,4]
  let len = toIntegral $ length l -- to avoid a type mismatch Integer &lt;-&gt; Int
  let l1 = zip l [1..]
  let l2 = map (\(x,y) -&gt; if y &lt; len then (x + 1,y) else (x,y)) l1
  let l3 = map (fst) l2
  </code></pre>
  
  <p>Not very nice...I do hope there is a better way! Since I'm a novice in functional programming, I don't know where to start looking for it though.</p>