EVOLUTION-MANAGER
Edit File: promise_reduce.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Promise-aware version of Reduce</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for promise_reduce {promises}"><tr><td>promise_reduce {promises}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Promise-aware version of Reduce</h2> <h3>Description</h3> <p>Similar to <code><a href="../../purrr/html/reduce.html">purrr::reduce</a></code> (left fold), but the function <code>.f</code> is permitted to return a promise. <code>promise_reduce</code> will wait for any returned promise to resolve before invoking <code>.f</code> with the next element; in other words, execution is serial. <code>.f</code> can return a promise as output but should never encounter a promise as input (unless <code>.x</code> itself is a list of promises to begin with, in which case the second parameter would be a promise). </p> <h3>Usage</h3> <pre> promise_reduce(.x, .f, ..., .init) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>.x</code></td> <td> <p>A vector or list to reduce. (Not a promise.)</p> </td></tr> <tr valign="top"><td><code>.f</code></td> <td> <p>A function that takes two parameters. The first parameter will be the "result" (initially <code>.init</code>, and then set to the result of the most recent call to <code>func</code>), and the second parameter will be an element of <code>.x</code>.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Other arguments to pass to <code>.f</code></p> </td></tr> <tr valign="top"><td><code>.init</code></td> <td> <p>The initial result value of the fold, passed into <code>.f</code> when it is first executed.</p> </td></tr> </table> <h3>Value</h3> <p>A promise that will resolve to the result of calling <code>.f</code> on the last element (or <code>.init</code> if <code>.x</code> had no elements). If any invocation of <code>.f</code> results in an error or a rejected promise, then the overall <code>promise_reduce</code> promise will immediately reject with that error. </p> <h3>Examples</h3> <pre> # Returns a promise for the sum of e1 + e2, with a 0.5 sec delay slowly_add <- function(e1, e2) { promise(~later::later(~resolve(e1 + e2), delay = 0.5)) } # Prints 55 after a little over 5 seconds promise_reduce(1:10, slowly_add, .init = 0) %...>% print() </pre> <hr /><div style="text-align: center;">[Package <em>promises</em> version 1.1.1 <a href="00Index.html">Index</a>]</div> </body></html>