Array.reduceBack<'T> Function (F#)

Applies a function to each element of the array, threading an accumulator argument through the computation. If the input function is f and the elements are i0...iN then computes f i0 (...(f iN-1 iN)). Raises ArgumentException if the array has size zero.

Namespace/Module Path: Microsoft.FSharp.Collections.Array

Assembly: FSharp.Core (in FSharp.Core.dll)

// Signature:
Array.reduceBack : ('T -> 'T -> 'T) -> 'T [] -> 'T

// Usage:
Array.reduceBack reduction array

Parameters

  • reduction
    Type: 'T -> 'T -> 'T

    The function to reduce a pair of elements to a single element.

  • array
    Type: 'T []

    The input array.

Exceptions

Exception

Condition

ArgumentException

Thrown when the input array is empty.

Return Value

The final result of the reductions.

Remarks

This function is named ReduceBack in compiled assemblies. If you are accessing the member from a language other than F#, or through reflection, use this name.

Example

The following code example compares Array.reduce and Array.reduceBack.

// Computes ((1 - 2) - 3) - 4 = -8
Array.reduce (fun elem acc -> elem - acc) [| 1; 2; 3; 4 |]
|> printfn "%A"
// Computes 1 - (2 - (3 - 4)) = -2
Array.reduceBack (fun elem acc -> elem - acc) [| 1; 2; 3; 4 |]
|> printfn "%A"

Output

-8
-2

Platforms

Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2

Version Information

F# Runtime

Supported in: 2.0, 4.0

Silverlight

Supported in: 3

See Also

Reference

Collections.Array Module (F#)

Microsoft.FSharp.Collections Namespace (F#)