public class Promise<T> extends java.lang.Object implements gnu.kawa.format.Printable, Lazy<T>
Constructor and Description |
---|
Promise()
Create new "blank" Promise.
|
Promise(Procedure thunk)
Create a new Promise that will evaluate thunk when forced.
|
Modifier and Type | Method and Description |
---|---|
Lazy |
checkAlias() |
void |
checkBlank() |
static Lazy<java.lang.Object> |
coerceToLazy(java.lang.Object value) |
static java.lang.Object |
force(java.lang.Object arg)
Forces the argument, if needed, to a non-Lazy value.
|
static java.lang.Object |
force(java.lang.Object arg,
java.lang.Class target)
If argument is Lazy, force it, unless already an instance of target.
|
static java.lang.Object |
force1(java.lang.Object arg)
Forces the argument, if needed.
|
T |
getValue()
Return the actual value.
|
boolean |
isBlank() |
static <T> Promise<T> |
makeBlank() |
static <T> Lazy<T> |
makeBoundPromise(T value)
Wrap value as a forced Promise.
|
void |
print(java.lang.Appendable out) |
void |
print(Consumer out) |
void |
setAlias(Lazy promise)
Bind promise to be an alias of another Lazy value.
|
void |
setException(java.lang.Throwable exception)
Bind this promise so forcing it throws the given exception.
|
void |
setForceValueIfPromise(boolean value)
Set whether to recursively call getValue if getValue yields a Lazy value.
|
void |
setThunk(Procedure thunk)
Bind this promise so forcing it evaluates the given procedure.
|
void |
setValue(java.lang.Object value)
Bind this promise to a given (eager) value.
|
java.lang.String |
toString() |
public Promise()
public Promise(Procedure thunk)
public void setForceValueIfPromise(boolean value)
public static <T> Promise<T> makeBlank()
public static <T> Lazy<T> makeBoundPromise(T value)
public static Lazy<java.lang.Object> coerceToLazy(java.lang.Object value)
public T getValue()
Lazy
getValue()
may return this
,
if this object isn't actually lazy.
It may also return another lazy value.
Normally you should use Promise.force{val}
to extra a non-lazy (eager) value.public final boolean isBlank()
public void checkBlank()
public void setValue(java.lang.Object value)
public void setAlias(Lazy promise)
public void setException(java.lang.Throwable exception)
public void setThunk(Procedure thunk)
public Lazy checkAlias()
public static java.lang.Object force1(java.lang.Object arg)
Lazy.getValue()
once if the argument is Lazy.public static java.lang.Object force(java.lang.Object arg)
Lazy.getValue()
as many times as needed.public static java.lang.Object force(java.lang.Object arg, java.lang.Class target)
public java.lang.String toString()
toString
in class java.lang.Object
public void print(Consumer out)
print
in interface gnu.kawa.format.Printable
public void print(java.lang.Appendable out) throws java.io.IOException
java.io.IOException