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

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

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

Tests if any element of the array satisfies the given predicate.

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

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


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

// Usage:
Array.exists predicate array


predicate Type: 'T ->bool

The function to test the input elements.

array Type: 'T[]

The input array.

Return Value

true if any result from predicate is true. Otherwise, false.


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

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


The following example demonstrates how to test the elements of an array by using Array.exists.

let allNegative = Array.exists (fun elem -> abs (elem) = elem) >> not
printfn "%A" (allNegative [| -1; -2; -3 |])
printfn "%A" (allNegative [| -10; -1; 5 |])
printfn "%A" (allNegative [| 0 |])


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