CumulativeFolded 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

Combines Mapped and Fold into a single function

function CumulativeFolded<'State, 'T> (fn : (('State, 'T) -> 'State), state : 'State, array : 'T[]) : 'State[]

Description

This function iterates the fn function through the array, starting from an initial state state and returns all intermediate values, not including the initial state.

Input

fn : ('State,'T) -> 'State

A function to be folded over the array

state : 'State

The initial state to be folded

array : 'T[]

An array of values to be folded over

Output : 'State[]

All intermediate states, including the final state, but not the initial state. The length of the output array is of the same length as array.

Type Parameters

'State

The type of states that the fn function operates on, i.e., accepts as its first input and returns.

'T

The type of array elements.

Example

// same as sums = [1, 3, 6, 10, 15]
let sums = CumulativeFolded(PlusI, 0, SequenceI(1, 5));