Expand Minimize

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

predicate

Type: 'T -> bool

A function to test each item of the input sequence.

source

Type: seq<'T>

The input sequence.

Exception

Condition

ArgumentNullException

Thrown when the input sequence is null.

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.

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 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

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

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft