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

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

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

For each element of the array, applies the given function. Concatenates all the results and return the combined array.

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

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

Syntax

// Signature:
Array.collect : ('T -> 'U []) -> 'T [] -> 'U []

// Usage:
Array.collect mapping array

Parameters

mapping Type: 'T -> 'U[]

The function to create sub-arrays from the input array elements.

array Type: 'T[]

The input array.

Return Value

The concatenation of the subarrays.

Remarks

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 Array.collect to concatenate subarrays that are generated from each array element.


printfn "%A" (Array.collect (fun elem -> [| 0 .. elem |]) [| 1; 5; 10|])
[|0; 1; 0; 1; 2; 3; 4; 5; 0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10|]

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.Array Module (F#)

Microsoft.FSharp.Collections Namespace (F#)

© 2017 Microsoft