Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

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

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: 'T list

The input list.

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.

The following code example illustrates the use of List.forall.

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

Output

true
false

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

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.