Pipe a possibly unresolved value forward into a function. The piped expression should be wrapped in .().

x %>>% f

.(expr)

Arguments

x

a 'mirai' or mirai value at $data that is possibly an 'unresolvedValue'.

f

a function that accepts 'x' as its first argument.

expr

a piped expression.

Value

The evaluated result, or if the mirai value of x is an 'unresolvedValue', an 'unresolvedExpr'.

It is advisable to wrap resolve() around a piped expression to ensure stability of return types, as this is guaranteed to return either an 'unresolvedExpr' or 'resolvedExpr'.

Details

An 'unresolvedExpr' encapsulates the eventual evaluation result. Query its $data element for resolution. Once resolved, the object changes into a 'resolvedExpr' and the evaluated result will be available at $data.

Supports stringing together a series of piped expressions (as per the below example).

Wrap a piped expression in .() to ensure that the return value is always an 'unresolvedExpr' or 'resolvedExpr' as the case may be, otherwise if 'x' is already resolved, the evaluated result would be returned directly.

unresolved may be used on an expression or its $data element to test for resolution.

Usage

Usage is similar to R's native |> pipe.

x %>>% f is equivalent to f(x)

x %>>% f() is equivalent to f(x)

x %>>% f(y) is equivalent to f(x, y)

Please note that other usage is not supported and it is not a drop-in replacement for magrittr's %>% pipe.

Examples

if (interactive()) {
# Only run examples in interactive R sessions

m <- mirai({Sys.sleep(0.5); 1})
b <- .(m %>>% c(2, 3) %>>% as.character)
unresolved(b)
b
b$data

call_mirai(m)
unresolved(b)
b
b$data

}