Enumerated 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

Given an array, returns a new array containing elements of the original array along with the indices of each element.

function Enumerated<'TElement> (array : 'TElement[]) : (Int, 'TElement)[]

Input

array : 'TElement[]

An array whose elements are to be enumerated.

Output : (Int,'TElement)[]

A new array containing elements of the original array along with their indices.

Type Parameters

'TElement

The type of elements of the array.

Example

The following for loops are equivalent:

for (idx in IndexRange(array)) {
    let element = array[idx];
    ...
}
for ((idx, element) in Enumerated(array)) { ... }