diff --git a/R/reduce.R b/R/reduce.R index d491ae1c..89c8996b 100644 --- a/R/reduce.R +++ b/R/reduce.R @@ -8,7 +8,22 @@ #' `f` over `1:3` computes the value `f(f(1, 2), 3)`. #' #' @inheritParams map -#' @param .y For `reduce2()` and `accumulate2()`, an additional +#' @param ... Additional arguments passed on to the reduce function. +#' +#' We now generally recommend against using `...` to pass additional +#' (constant) arguments to `.f`. Instead use a shorthand anonymous function: +#' +#' ```R +#' # Instead of +#' x |> reduce(f, 1, 2, collapse = ",") +#' # do: +#' x |> reduce(\(x, y) f(x, y, 1, 2, collapse = ",")) +#' ``` +#' +#' This makes it easier to understand which arguments belong to which +#' function and will tend to yield better error messages. +#' +#' @param .y For `reduce2()` an additional #' argument that is passed to `.f`. If `init` is not set, `.y` #' should be 1 element shorter than `.x`. #' @param .f For `reduce()`, a 2-argument function. The function will be passed diff --git a/man/reduce.Rd b/man/reduce.Rd index 69ea6388..470f5f73 100644 --- a/man/reduce.Rd +++ b/man/reduce.Rd @@ -23,15 +23,15 @@ second argument, and the next value of \code{.y} as the third argument. The reduction terminates early if \code{.f} returns a value wrapped in a \code{\link[=done]{done()}}.} -\item{...}{Additional arguments passed on to the mapped function. +\item{...}{Additional arguments passed on to the reduce function. We now generally recommend against using \code{...} to pass additional (constant) arguments to \code{.f}. Instead use a shorthand anonymous function: \if{html}{\out{
}}\preformatted{# Instead of -x |> map(f, 1, 2, collapse = ",") +x |> reduce(f, 1, 2, collapse = ",") # do: -x |> map(\\(x) f(x, 1, 2, collapse = ",")) +x |> reduce(\\(x, y) f(x, y, 1, 2, collapse = ",")) }\if{html}{\out{
}} This makes it easier to understand which arguments belong to which @@ -46,7 +46,7 @@ is empty. If missing, and \code{.x} is empty, will throw an error.} \code{"forward"} (the default) or \code{"backward"}. See the section about direction below.} -\item{.y}{For \code{reduce2()} and \code{accumulate2()}, an additional +\item{.y}{For \code{reduce2()} an additional argument that is passed to \code{.f}. If \code{init} is not set, \code{.y} should be 1 element shorter than \code{.x}.} } diff --git a/man/reduce_right.Rd b/man/reduce_right.Rd index f3478e4f..8d80bcd8 100644 --- a/man/reduce_right.Rd +++ b/man/reduce_right.Rd @@ -26,15 +26,15 @@ second argument, and the next value of \code{.y} as the third argument. The reduction terminates early if \code{.f} returns a value wrapped in a \code{\link[=done]{done()}}.} -\item{...}{Additional arguments passed on to the mapped function. +\item{...}{Additional arguments passed on to the reduce function. We now generally recommend against using \code{...} to pass additional (constant) arguments to \code{.f}. Instead use a shorthand anonymous function: \if{html}{\out{
}}\preformatted{# Instead of -x |> map(f, 1, 2, collapse = ",") +x |> reduce(f, 1, 2, collapse = ",") # do: -x |> map(\\(x) f(x, 1, 2, collapse = ",")) +x |> reduce(\\(x, y) f(x, y, 1, 2, collapse = ",")) }\if{html}{\out{
}} This makes it easier to understand which arguments belong to which @@ -45,7 +45,7 @@ the accumulation, rather than using \code{.x[[1]]}. This is useful if you want to ensure that \code{reduce} returns a correct value when \code{.x} is empty. If missing, and \code{.x} is empty, will throw an error.} -\item{.y}{For \code{reduce2()} and \code{accumulate2()}, an additional +\item{.y}{For \code{reduce2()} an additional argument that is passed to \code{.f}. If \code{init} is not set, \code{.y} should be 1 element shorter than \code{.x}.} }