Promise-class: Promises

Promise-classR Documentation



The Promise class formally and abstractly represents the potential result of a deferred computation.


Lazy programming is useful in a number of contexts, including interaction with external/remote systems like databases, where we want the computation to occur within the external system, despite appearances to the contrary. Typically, the user constructs one or more promises referring to pre-existing objects. Operations on those objects produce new promises that encode the additional computations. Eventually, usually after some sort of restriction and/or aggregation, the promise is “fulfilled” to yield a materialized, eager object, such as an R vector.

Promise and its partial implementation SimplePromise provide a foundation for implementations that mostly helps with creating and fulfilling promises, while the implementation is responsible for deferring particular computations, which is language-dependent.


  • Promise(expr, context, ...): A generic constructor that dispatches on expr to construct a Promise object, the specific type of which corresponds to the language of expr. The context argument should be a Context object, in which expr will be evaluated when the promise is fulfilled. The ... are passed to methods.


  • fulfill(x): Fulfills the promise by evaluating the deferred computation and returning a materialized object.

The basic coercion functions in R, like as.vector and, have methods for Promise that simply call fulfill on the promise, and then perform the coercion. Coercion is preferred to calling fulfill directly.


Michael Lawrence

rsolr documentation built on May 18, 2022, 9:07 a.m.