What's an alternative to Seq.iter so that I can return the result of the operation for the last item?
<p><strong>What's an alternative to Seq.iter so that I can return the result of the operation for the last item?</strong></p>

<p>Seq.iter returns a unit. However, I want to iterate through my collection and return the last result.</p>

<p><strong>Consider the following code:</strong></p>

<pre><code>let updatedGrid = grid |&gt; Map.toSeq
                       |&gt; Seq.map snd
                       |&gt; Seq.iter (fun c -&gt; grid |&gt; setCell c 
</code></pre>

<p>NOTE: SetCell returns a new Map:</p>

<p><strong>Here's the actual code:</strong></p>

<pre><code>let setCell cell (grid:Map&lt;(int * int), Cell&gt;) =

    grid |&gt; Map.map (fun k v -&gt; match k with
                                | c when c = (cell.X, cell.Y) -&gt; { v with State=cell.State }
                                | _ -&gt; v)

let cycleThroughCells (grid:Map&lt;(int * int), Cell&gt;) =

    let updatedGrid = grid |&gt; Map.toSeq
                           |&gt; Seq.map snd
                           |&gt; Seq.iter (fun c -&gt; grid |&gt; setCell c 
                                                      |&gt; ignore) 
    updatedGrid
</code></pre>

<p>Again, I just want to take the result of the last operation in the iter function</p>

<p><strong>[UPDATED]</strong></p>

<p>I think this works (using map):</p>

<pre><code>let cycleThroughCells (grid:Map&lt;(int * int), Cell&gt;) =

    let updatedGrid = grid |&gt; Map.toSeq
                           |&gt; Seq.map snd
                           |&gt; Seq.map (fun c -&gt; grid |&gt; setCell c) 
                           |&gt; Seq.last
    updatedGrid
</code></pre>