Seq.iteri<'T> Function (F#)
Visual Studio 2012
Applies the given function to each element of the collection. The integer passed to the function indicates the index of element.
Namespace/Module Path: Microsoft.FSharp.Collections.Seq
Assembly: FSharp.Core (in FSharp.Core.dll)
// Signature: Seq.iteri : (int -> 'T -> unit) -> seq<'T> -> unit // Usage: Seq.iteri action source
The following code shows how to use Seq.iteri and compares its behavior to related functions.
let seq1 = [1; 2; 3] let seq2 = [4; 5; 6] Seq.iter (fun x -> printfn "Seq.iter: element is %d" x) seq1 Seq.iteri(fun i x -> printfn "Seq.iteri: element %d is %d" i x) seq1 Seq.iter2 (fun x y -> printfn "Seq.iter2: elements are %d %d" x y) seq1 seq2
Output
Seq.iter: element is 1 Seq.iter: element is 2 Seq.iter: element is 3 Seq.iteri: element 0 is 1 Seq.iteri: element 1 is 2 Seq.iteri: element 2 is 3 Seq.iter2: elements are 1 4 Seq.iter2: elements are 2 5 Seq.iter2: elements are 3 6