MappedOverRange 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 a range and a function that takes an integer as input, returns a new array that consists of the images of the range values under the function.

function MappedOverRange<'T> (mapper : (Int -> 'T), range : Range) : 'T[]

Input

mapper : Int -> 'T

A function from Int to 'T that is used to map range values.

range : Range

A range of integers.

Output : 'T[]

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

Type Parameters

'T

The result type of the mapper function.

Example

This example adds 1 to a range of even numbers:

let numbers = MappedOverRange(PlusI(1, _), 0..2..10);
// numbers = [1, 3, 5, 7, 9, 11]

Remarks

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

See Also