title: F# iterate over collection and build list
body: <p>I'm a .Net developer but new to F# and functional programming in general. Could someone point me in the right direction on the following problem:</p>
  
  <p>I'm trying to iterate through a sequence of data I've read from CSV and build a sort of summary list. Pseudo-code is</p>
  
  <pre><code>type record = { Name:string; Time:DateTime;}
  
  type summary = {Name:String; Start:DateTime; End:DateTime}
  </code></pre>
  
  <p>Example data: 
   (Name Time)</p>
  
  <ul>
  <li>A 10:01</li>
  <li>A 10:02</li>
  <li>A 10:03</li>
  <li>B 11:15</li>
  <li>B 11:25</li>
  <li>B 11:30</li>
  <li>C 12:00</li>
  <li>A 13:01</li>
  <li>A 13:05</li>
  </ul>
  
  <p>I'm trying to iterate through the sequence and build a second sequence: </p>
  
  <pre><code>Seq&lt;Summary&gt;
  </code></pre>
  
  <p>(Name Start End)</p>
  
  <ul>
  <li>A 10:01 10:03</li>
  <li>B 11:15 11:30</li>
  <li>C 12:00 12:00</li>
  <li>A 13:01 13:05</li>
  </ul>
  
  <p>Should I be piping the <code>seq&lt;record&gt;</code> to a function which iterates though in a <code>foreach</code> style, or is there a better way to do it? I have sorted the data in F# so the data is in time order. I don't have to worry about them being out of order.</p>
  
  <p>If it were C# I'd probably do something like (Pseudo-code):</p>
  
  <pre><code>List&lt;Summary&gt; summaryData
  
  foreach(var r in records)
  {
     Summary last =  summaryData.LastOrDefault()
  
     if(last == null)
     {
        summaryData.add( new Summary from r)
     }
     else
     {
       if(last.Name = r.Name)
       {
             last.End = r.Time
       } 
       else
       {
             summaryData.add( new Summary from r)
       }
  
  } 
  </code></pre>
  
  <p>Any help greatly appreciated!</p>