# fold: Efficient fold / reduce / accumulate / combine of a vector In furrr: Apply Mapping Functions in Parallel using Futures

## Description

This function comes from the `future.apply` package.

## Usage

 `1` ```fold(x, f, left = TRUE, unname = TRUE, threshold = 1000L) ```

## Arguments

 `x` A vector. `f` A binary function, i.e. a function take takes two arguments. `left` If `TRUE`, vector is combined from the left (the first element), otherwise the right (the last element). `unname` If `TRUE`, function `f` is called as `f(unname(y), x[[ii]])`, otherwise as `f(y, x[[ii]])`, which may introduce name `"y"`. [[ii]: R:[ii [[ii]: R:[ii `threshold` An integer (>= 2) specifying the length where the recursive divide'and'conquer call will stop and incremental building of the partial value is performed. Using `threshold = +Inf` will disable recursive folding.

## Details

In order for recursive folding to give the same results as non-recursive folding, binary function `f` must be associative with itself, i.e. `f(f(x[], x[]), x[])` equals `f(x[], f(x[]), x[])`.

This function is a more efficient (memory and speed) of [`base::Reduce(f, x, right = !left, accumulate = FALSE)`][base::Reduce], especially when `x` is long.

[: R:[1 [: R:[2 [: R:[3 [: R:[1 [: R:[2 [: R:[3 [base::Reduce]: R:base::Reduce

## Value

A vector.

furrr documentation built on May 2, 2019, 1:04 p.m.