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

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

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

Returns a sequence that, when iterated, yields elements of the underlying sequence while the given predicate returns true, and then returns no further elements.

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

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

Syntax

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

// Usage:
Seq.takeWhile predicate source

Parameters

predicate Type: 'T ->bool

A function that evaluates to false when no more items should be returned.

source Type: seq<'T>

The input sequence.

Exceptions

ExceptionCondition
ArgumentNullExceptionThrown when the input sequence is null.

Return Value

The result sequence.

Remarks

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

Example

The following example demonstrates the use of Seq.takeWhile. The sequence contains squares of integers that are less than 10.


    let mySeq = seq { for i in 1 .. 10 -> i*i }
    let printSeq seq1 = Seq.iter (printf "%A ") seq1; printfn ""
    let mySeqLessThan10 = Seq.takeWhile (fun elem -> elem < 10) mySeq
    mySeqLessThan10 |> printSeq
1 4 9

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