File: promise_map.Rd

package info (click to toggle)
r-cran-promises 1.3.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,440 kB
  • sloc: cpp: 45; sh: 13; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 1,486 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{promise_map}
\alias{promise_map}
\title{Promise-aware lapply/map}
\usage{
promise_map(.x, .f, ...)
}
\arguments{
\item{.x}{A vector (atomic or list) or an expression object (but not a
promise). Other objects (including classed objects) will be coerced by
base::as.list.}

\item{.f}{The function to be applied to each element of \code{.x}. The function is
permitted, but not required, to return a promise.}

\item{...}{Optional arguments to \code{.f}.}
}
\value{
A promise that resolves to a list (of values, not promises).
}
\description{
Similar to \code{\link[base:lapply]{base::lapply()}} or \code{\link[purrr:map]{purrr::map}}, but promise-aware: the \code{.f}
function is permitted to return promises, and while \code{lapply} returns a list,
\code{promise_map} returns a promise that resolves to a similar list (of resolved
values only, no promises).
}
\details{
\code{promise_map} processes elements of \code{.x} serially; that is, if \code{.f(.x[[1]])}
returns a promise, then \code{.f(.x[[2]])} will not be invoked until that promise
is resolved. If any such promise rejects (errors), then the promise returned
by \code{promise_map} immediately rejects with that err.
}
\examples{
# Waits x seconds, then returns x*10
wait_this_long <- function(x) {
  promise(~later::later(~{
    resolve(x*10)
  }, delay = x))
}

promise_map(list(A=1, B=2, C=3), wait_this_long) \%...>\%
  print()

}