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

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

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

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.


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


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.


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


For sequence seq [0; 1; 2; 3], contains zero is true


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.Seq Module (F#)

Microsoft.FSharp.Collections Namespace (F#)

© 2020 Microsoft