| Promise-class {rsolr} | R Documentation |
Promises
Description
The Promise class formally and abstractly represents the
potential result of a deferred computation.
Details
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.
Construction
-
Promise(expr, context, ...): A generic constructor that dispatches onexprto construct aPromiseobject, the specific type of which corresponds to the language ofexpr. Thecontextargument should be aContextobject, in whichexprwill be evaluated when the promise is fulfilled. The...are passed to methods.
Fulfillment
-
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
as.data.frame, have methods for Promise that simply call
fulfill on the promise, and then perform the coercion. Coercion
is preferred to calling fulfill directly.
Author(s)
Michael Lawrence