Export (0) Print
Expand All
Expand Minimize

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

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.

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

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

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

Show:
© 2014 Microsoft