Partitioned function

Warning

This documentation refers to the Classic QDK, which has been replaced by the Modern QDK.

Please see https://aka.ms/qdk.api for the API documentation for the Modern QDK.

Namespace: Microsoft.Quantum.Arrays

Package: Microsoft.Quantum.Standard

Splits an array into multiple parts.

function Partitioned<'T> (nElements : Int[], arr : 'T[]) : 'T[][]

Input

nElements : Int[]

Number of elements in each part of array

arr : 'T[]

Input array to be split.

Output : 'T[][]

Multiple arrays where the first array is the first nElements[0] of arr and the second array are the next nElements[1] of arr etc. The last array will contain all remaining elements. If the array is split exactly, the last array will be the empty array, indicating there are no remaining elements. In other words, Tail(Partitioned(...)) will always return the remaining elements, while Most(Partitioned(...)) will always return the complete partitions of the array.

Type Parameters

'T

Example

// The following returns [[1, 5], [3], [7]];
let split = Partitioned([2,1], [1,5,3,7]);
// The following returns [[1, 5], [3, 7], []];
let split = Partitioned([2,2], [1,5,3,7]);