Table of contents
Collapse the table of content
Expand the table of content

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

Den Delimarsky|Last Updated: 8/18/2017
1 Contributor

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


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.


ArgumentExceptionThrown when the input sequence is empty.
ArgumentNullExceptionThrown when the input sequence is null.

Return Value

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


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.


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




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

Collections.Seq Module (F#)

Microsoft.FSharp.Collections Namespace (F#)

© 2020 Microsoft