title: How to enumerate with a reference to the previous element, in Elixir/Erlang
body: <p>I need to normalize a list of elements before applying <code>Enum.chunk_by</code> to the list.</p>
  
  <p>Typically when we enumerate we go item by item, for example</p>
  
  <pre><code>source_list |&gt; normalize_item
  </code></pre>
  
  <p>How may we enumerate while referencing previous element in the list?</p>
  
  <p>Also, how may we keep a reference to the last normalized_item on the next iteration?</p>
  
  <p>Sample Data:</p>
  
  <pre><code>[
  %PhoneBills.Text{end: 91, page: 13, row: 237, start: 48, text: "2348035250601"},
  %PhoneBills.Text{end: 155, page: 13, row: 237, start: 99, text: "17-12-2014 10:08:32"},
  %PhoneBills.Text{end: 247, page: 13, row: 238, start: 168, text: "1080643204171320 2811630"},
  %PhoneBills.Text{end: 286, page: 13, row: 238, start: 268, text: "400.00"},
  %PhoneBills.Text{end: 394, page: 13, row: 238, start: 370, text: "Payment"},
  %PhoneBills.Text{end: 91, page: 13, row: 244, start: 48, text: "2348035250601"},
  %PhoneBills.Text{end: 155, page: 13, row: 244, start: 99, text: "17-12-2014 10:09:12"},
  %PhoneBills.Text{end: 247, page: 13, row: 246, start: 168, text: "1775292204171752 2811630"},
  %PhoneBills.Text{end: 286, page: 13, row: 246, start: 268, text: "400.00"},
  %PhoneBills.Text{end: 394, page: 13, row: 246, start: 370, text: "Payment"},
  %PhoneBills.Text{end: 91, page: 13, row: 252, start: 48, text: "2348068014410"},
  %PhoneBills.Text{end: 155, page: 13, row: 252, start: 99, text: "17-12-2014 08:34:23"},
  %PhoneBills.Text{end: 250, page: 13, row: 254, start: 168, text: "174729900817063 100153465"},
  %PhoneBills.Text{end: 286, page: 13, row: 254, start: 263, text: "1,500.00"},
  %PhoneBills.Text{end: 394, page: 13, row: 254, start: 370, text: "Payment"}
  ]
  </code></pre>
  
  <p>I need to normalize the <code>row</code> fields above, where two adjacent elements are actually on the same row, if their difference is <code>&lt;= 2</code>, before applying <code>Enum.chunk_by</code> to the list</p>
  
  <p>I have considered <code>Enum.chunk_while</code> but it does not offer a good solution in this case.</p>
  
  <p>Expected output:</p>
  
  <pre><code>[
  %PhoneBills.Text{end: 91, page: 13, row: 237, start: 48, text: "2348035250601"},
  %PhoneBills.Text{end: 155, page: 13, row: 237, start: 99, text: "17-12-2014 10:08:32"},
  %PhoneBills.Text{end: 247, page: 13, row: 237, start: 168, text: "1080643204171320 2811630"},
  %PhoneBills.Text{end: 286, page: 13, row: 237, start: 268, text: "400.00"},
  %PhoneBills.Text{end: 394, page: 13, row: 237, start: 370, text: "Payment"},
  %PhoneBills.Text{end: 91, page: 13, row: 244, start: 48, text: "2348035250601"},
  %PhoneBills.Text{end: 155, page: 13, row: 244, start: 99, text: "17-12-2014 10:09:12"},
  %PhoneBills.Text{end: 247, page: 13, row: 244, start: 168, text: "1775292204171752 2811630"},
  %PhoneBills.Text{end: 286, page: 13, row: 244, start: 268, text: "400.00"},
  %PhoneBills.Text{end: 394, page: 13, row: 244, start: 370, text: "Payment"},
  %PhoneBills.Text{end: 91, page: 13, row: 252, start: 48, text: "2348068014410"},
  %PhoneBills.Text{end: 155, page: 13, row: 252, start: 99, text: "17-12-2014 08:34:23"},
  %PhoneBills.Text{end: 250, page: 13, row: 252, start: 168, text: "174729900817063 100153465"},
  %PhoneBills.Text{end: 286, page: 13, row: 252, start: 263, text: "1,500.00"},
  %PhoneBills.Text{end: 394, page: 13, row: 252, start: 370, text: "Payment"}
  ]
  </code></pre>