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

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

Mark Seemann|Last Updated: 8/18/2017
1 Contributor

Splits the collection into two collections, before the given index.

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

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


// Signature:
List.splitAt : int -> 'T list -> 'T list * 'T list

// Usage:
List.splitAt index list


index Type: int

The zero-based index at which the list should be split.

list Type: 'Tlist

The input list.

Return Value

A list containing all the elements before the index, and a list containing all the elements at, and after, the index.


The function splits the input list into two lists. The element at the zero-based index goes into the second list. As a consequence of this, if index is 0, the first list will be empty. Likewise, if the index is exactly equal to the length of the list, the second list will be empty.

If the index is higher than the length of the list, an exception is thrown.

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


let first, second = List.splitAt 2 [0..9]
printfn "First: %A\nSecond: %A" first second


First: [0; 1]
Second: [2; 3; 4; 5; 6; 7; 8; 9]


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#)

© 2020 Microsoft