Export (0) Print
Expand All
Expand Minimize

Array.reduce<'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 (... (f i0 i1)...) 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.reduce : ('T -> 'T -> 'T) -> 'T [] -> 'T

// Usage:
Array.reduce reduction array


Type: 'T -> 'T -> 'T

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


Type: 'T []

The input array.




Thrown when the input array is empty.

The final result of the reductions.

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

The following example demonstrates the use of Array.reduce.

let names = [| "A"; "man"; "landed"; "on"; "the"; "moon" |]
let sentence = names |> Array.reduce (fun acc item -> acc + " " + item)
printfn "sentence = %s" sentence
sentence = A man landed on the moon

Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

© 2015 Microsoft