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

List.chunkBySize<'T> Function (F#)

Jonathan Banashek|Last Updated: 8/18/2017
|
1 Contributor

Divides the input list into chunks of size at most chunkSize.

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

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

Syntax

// Signature:
List.chunkBySize: chunkSize:int -> list:'T list -> 'T list list

// Usage:
List.chunkBySize chunkSize list

Parameters

chunkSize Type: int

The maximum size of each chunk.

list Type: 'Tlist

The input list.

Exceptions

ExceptionCondition
ArgumentExceptionThrown when chunkSize is not positive.

Return Value

The input list divided into chunks.

Remarks

This function is named ChunkBySize 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 shows how to use List.chunkBySize.

let list1 = [ 1 .. 10 ]

// The following chunks the list into sub-lists of size 2
printfn "%A" (List.chunkBySize 2 list1)

// The following chunks the list into sub-lists of size 3, with the last list being a single element
printfn "%A" (List.chunkBySize 3 list1)

Output

[[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: 4.0, Portable

See Also

Collections.List Module (F#)

Microsoft.FSharp.Collections Namespace (F#)

© 2018 Microsoft