Expand Minimize

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

Tests if all corresponding elements of the array satisfy the given predicate pairwise.

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

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

// Signature:
Array.forall2 : ('T1 -> 'T2 -> bool) -> 'T1 [] -> 'T2 [] -> bool

// Usage:
Array.forall2 predicate array1 array2


Type: 'T1 -> 'T2 -> bool

The function to test the input elements.


Type: 'T1 []

The first input array.


Type: 'T2 []

The second input array.




Thrown when the input arrays differ in length.

true if all of the array elements satisfy the predicate. Otherwise, returns false.

The predicate is applied to matching elements in the two collections up to the lesser of the two lengths of the collections. If any application returns false then the overall result is false and no further elements are tested. Otherwise, if one collection is longer than the other, then the ArgumentException exception is raised.

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

The following example shows the use of Array.forall2 to test the equality of all the elements in two arrays.

let allEqual = Array.forall2 (fun elem1 elem2 -> elem1 = elem2)
printfn "%A" (allEqual [| 1; 2 |] [| 1; 2 |])
printfn "%A" (allEqual [| 1; 2 |] [| 2; 1 |])


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

F# Runtime

Supported in: 2.0, 4


Supported in: 3

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft