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

Tests whether all the pairs of elements drawn from the two sequences satisfy the given predicate. 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.forall2 : ('T1 -> 'T2 -> bool) -> seq<'T1> -> seq<'T2> -> bool

// Usage:
Seq.forall2 predicate source1 source2

Parameters

  • predicate
    Type: 'T1 -> 'T2 -> bool

    A function to test pairs 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.

Return Value

true if all element pairs in the sequences satisfy the given predicate. Otherwise, returns false.

Remarks

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

Example

The following code shows how to use Seq.forall2.

// This function can be used on any sequence, so the same function
// works with both lists and arrays.
let allEqual = Seq.forall2 (fun elem1 elem2 -> elem1 = elem2)
printfn "%A" (allEqual [| 1; 2 |] [| 1; 2 |])
printfn "%A" (allEqual [ 1; 2 ] [ 2; 1 ])

Output

true
false

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#)