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


Type: 'T -> bool

The function to test the input elements.


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

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

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

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