Seq.exists<'T> Function (F#)
Tests if any element of the sequence satisfies the given predicate.
Namespace/Module Path: Microsoft.FSharp.Collections.Seq
Assembly: FSharp.Core (in FSharp.Core.dll)
// Signature:
Seq.exists : ('T -> bool) -> seq<'T> -> bool
// Usage:
Seq.exists predicate source
Parameters
predicate
Type: 'T ->boolA function to test each item of the input sequence.
source
Type: seq<'T>The input sequence.
Exceptions
Exception |
Condition |
---|---|
Thrown when the input sequence is null. |
Return Value
The predicate is applied to the elements of the input sequence. If any application returns true then the overall result is true and no further elements are tested. Otherwise, returns false.
Remarks
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.
Example
The following code shows how to use Seq.exists.
// Use Seq.exists to determine whether there is an element of a sequence
// that satisfies a given Boolean expression.
// containsNumber returns true if any of the elements of the supplied sequence match
// the supplied number.
let containsNumber number seq1 = Seq.exists (fun elem -> elem = number) seq1
let seq0to3 = seq {0 .. 3}
printfn "For sequence %A, contains zero is %b" seq0to3 (containsNumber 0 seq0to3)
Output
For sequence seq [0; 1; 2; 3], contains zero is 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