Compartilhar via


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 coll = Seq.forall2 (fun elem1 elem2 -> elem1 = elem2) coll
printfn "%A" (allEqual [| 1; 2 |] [| 1; 2 |])
printfn "%A" (allEqual [ 1; 2 ] [ 2; 1 ])

Output

true
false

Platforms

Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

Version Information

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

See Also

Reference

Collections.Seq Module (F#)

Microsoft.FSharp.Collections Namespace (F#)