title: Does ruby support an enumerable map_cons method or its equivalent?
body: <p>Ruby has a handy function for enumerables called <a href="https://ruby-doc.org/core-2.4.2/Enumerable.html#method-i-each_cons" rel="noreferrer"><code>each_cons</code></a>.  Which "Iterates the given block for each array of consecutive  elements."  This is really nice.  Except that this is definitely an <code>each</code> method, which returns nil upon completion and not an array of the values you've looped over like <code>map</code> would.</p>
  
  <p>However, if I have a situation where I need to iterate over an enumerable type, take an element and its cons, then perform some operation on them and return them back into an array what can I do?  Normally, I'd use map for this sort of behavior.  But <code>map_cons</code> doesn't exist.  </p>
  
  <p>An example:</p>
  
  <p>Given a list of integers, I need to see which ones of those integers repeat and return a list of just those integers</p>
  
  <pre><code>[1, 1, 4, 5, 6, 2, 2] ## I need some function that will get me [1, 2]
  </code></pre>
  
  <p>I can say:</p>
  
  <pre><code>[1, 1, 4, 5, 6, 2, 2].each_cons(2) {|e| e[0] if e[0] == e[1]}
  </code></pre>
  
  <p>But, since it <code>each</code>s over the array, it will complete successfully and return <code>nil</code> at the end.  I need it to behave like <code>map</code> and not like <code>each</code>. </p>
  
  <p>Is this behavior something that ruby supports? Am I coming at it from the wrong direction entirely?</p>