Seq.iter2<'T1,'T2> Function (F#)

Applies the given function to two collections simultaneously. If one sequence is shorter than the other then the remaining elements of the longer sequence are ignored.

Namespace/Module Path: Microsoft.FSharp.Collections.Seq

Assembly: FSharp.Core (in FSharp.Core.dll)

// Signature:
Seq.iter2 : ('T1 -> 'T2 -> unit) -> seq<'T1> -> seq<'T2> -> unit

// Usage:
Seq.iter2 action source1 source2

Parameters

  • action
    Type: 'T1 -> 'T2 -> unit

    A function to apply to each pair of elements from the input sequences.

  • source1
    Type: seq<'T1>

    The first input sequence.

  • source2
    Type: seq<'T2>

    The second input sequence.

Exceptions

Exception

Condition

ArgumentNullException

Thrown when either of the input sequences is null.

Remarks

This function is named Iterate2 in compiled assemblies. If you are accessing the function from a .NET language other than F#, or through reflection, use this name.

Example

The following code shows how to use Seq.iter2 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

Platforms

Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2

Version Information

F# Runtime

Supported in: 2.0, 4.0

Silverlight

Supported in: 3

See Also

Reference

Collections.Seq Module (F#)

Microsoft.FSharp.Collections Namespace (F#)