MappedByIndex 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 and a function that is defined for the indexed elements of the array, returns a new array that consists of the images of the original array under the function.

function MappedByIndex<'T, 'U> (mapper : ((Int, 'T) -> 'U), array : 'T[]) : 'U[]

Input

mapper : (Int,'T) -> 'U

A function from (Int, 'T) to 'U that is used to map elements and their indices.

array : 'T[]

An array of elements over 'T.

Output : 'U[]

An array 'U[] of elements that are mapped by the mapper function.

Type Parameters

'T

The type of array elements.

'U

The result type of the mapper function.

Example

The following two lines are equivalent:

let arr = MapIndex(f, [x0, x1, x2]);

and

let arr = [f(0, x0), f(1, x1), f(2, x2)];

Remarks

The function is defined for generic types, i.e., whenever we have an array 'T[] and a function mapper: (Int, 'T) -> 'U we can map the elements of the array and produce a new array of type 'U[].

See Also