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

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

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

For each element of the list, applies the given function. Concatenates all the results and returns the combined list.

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

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


// Signature:
List.collect : ('T -> 'U list) -> 'T list -> 'U list

// Usage:
List.collect mapping list


mapping Type: 'T -> 'Ulist

The function to transform each input element into a sublist to be concatenated.

list Type: 'Tlist

The input list.

Return Value

The concatenation of the resulting sublists.


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


let list1 = [10; 20; 30]
let collectList = List.collect (fun x -> [for i in 1..3 -> x * i]) list1
printfn "%A" collectList


[10; 20; 30; 20; 40; 60; 30; 60; 90]


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

Microsoft.FSharp.Collections Namespace (F#)

© 2020 Microsoft