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

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

Den Delimarsky|Last Updated: 7/25/2016
|
1 Contributor

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

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

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

Syntax

// Signature:
Seq.forall : ('T -> bool) -> seq<'T> -> bool

// Usage:
Seq.forall predicate source

Parameters

predicate Type: 'T ->bool

A function to test an element of the input sequence.

source Type: seq<'T>

The input sequence.

Exceptions

ExceptionCondition
ArgumentNullExceptionThrown when the input sequence is null.

Return Value

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

Remarks

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

Example


    // This function can be used on any sequence, so the same function
    // works with both lists and arrays.
    let allPositive coll = Seq.forall (fun elem -> elem > 0) coll
    printfn "%A" (allPositive [| 0; 1; 2; 3 |])
    printfn "%A" (allPositive [ 1; 2; 3 ])

Output

false
true

Platforms

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

© 2016 Microsoft