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

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

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

Tests if all elements of the collection satisfy the given predicate.

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

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


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

// Usage:
List.forall predicate list


predicate Type: 'T ->bool

The function to test the input elements.

list Type: 'Tlist

The input list.

Return Value

true if all of the elements satisfy the predicate. Otherwise, returns false.


The predicate is applied to the elements of the input list. If any application returns false then the overall result is false and no further elements are tested. Otherwise, true is returned.

This function is named ForAll in compiled assemblies. If you are accessing the function from a language other than F#, or through reflection, use this name.


let isAllZeroes list = List.forall (fun elem -> elem = 0.0) list
printfn "%b" (isAllZeroes [0.0; 0.0])
printfn "%b" (isAllZeroes [0.0; 1.0])




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