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

Parameters

  • predicate
    Type: 'T ->bool

    The function to test the input elements.

  • array
    Type: 'T[]

    The input array.

Return Value

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

Remarks

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.

Example

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

Platforms

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

Reference

Collections.Array Module (F#)

Microsoft.FSharp.Collections Namespace (F#)