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

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

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

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.

Result Value

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

Version Information

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

See Also

Collections.Array Module (F#)

Microsoft.FSharp.Collections Namespace (F#)

© 2020 Microsoft