Expand Minimize

Array.forall<'T> Function (F#)

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

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

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

// Signature:
Array.forall : ('T -> bool) -> 'T [] -> bool

// Usage:
Array.forall predicate array

predicate

Type: 'T -> bool

The function to test the input elements.

array

Type: 'T []

The input array.

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

The predicate is applied to the elements of the input collection. If any application returns false then the overall result is false and no further elements are tested.

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

The following example shows the use of Array.forall to test the elements of an array.


let allPositive = Array.forall (fun elem -> elem > 0)
printfn "%A" (allPositive [| 0; 1; 2; 3 |])
printfn "%A" (allPositive [| 1; 2; 3 |])


false
true

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.0

Silverlight

Supported in: 3

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

Community Additions

ADD
Show:
© 2014 Microsoft