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

Seq.collect<'T,'Collection,'U> Function (F#)

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

Applies the given function to each element of the sequence and concatenates all the results.

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

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

Syntax

// Signature:
Seq.collect : ('T -> 'Collection) -> seq<'T> -> seq<'U> (requires 'Collection :> seq<'U>)

// Usage:
Seq.collect mapping source

Parameters

mapping Type: 'T -> 'Collection

A function to transform elements of the input sequence into the sequences that are concatenated.

source Type: seq<'T>

The input sequence.

Exceptions

ExceptionCondition
ArgumentNullExceptionThrown when the input sequence is null

Return Value

The result sequence.

Remarks

The sequence is evaluated lazily. Therefore, effects are delayed until it is enumerated.

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

Example

The following code demonstrates the use of Seq.collect.


    let addNegations seq1 =
       Seq.collect (fun x -> seq { yield x; yield -x }) seq1
       |> Seq.sort
    addNegations [ 1 .. 4 ] |> Seq.iter (fun elem -> printf "%d " elem)
    printfn ""
    addNegations [| 0; -4; 2; -12 |] |> Seq.iter (fun elem -> printf "%d " elem)

Output

-4 -3 -2 -1 1 2 3 4
-12 -4 -2 0 0 2 4 12

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