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

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

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

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

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

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


// Signature:
List.exists : ('T -> bool) -> 'T list -> bool

// Usage:
List.exists predicate list


predicate Type: 'T ->bool

The function to test the input elements.

list Type: 'Tlist

The input list.

Return Value

true if any element satisfies the predicate. Otherwise, returns false.


The predicate is applied to the elements of the input list. 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 code illustrates the use of List.exists to determine whether a given element exists in a list.

// Use List.exists to determine whether there is an element of a list satisfies a given Boolean expression.
// containsNumber returns true if any of the elements of the supplied list match 
// the supplied number.
let containsNumber number list = List.exists (fun elem -> elem = number) list
let list0to3 = [0 .. 3]
printfn "For list %A, contains zero is %b" list0to3 (containsNumber 0 list0to3)


For list [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.List Module (F#)

Microsoft.FSharp.Collections Namespace (F#)

© 2020 Microsoft