Package gnu.mapping
Class Promise<T>
java.lang.Object
gnu.mapping.Promise<T>
- All Implemented Interfaces:
gnu.kawa.format.Printable
,Lazy<T>
Implement Scheme "promises".
This is a final class, because in some cases (as required by SRFI-45)
we copy the fields of one Promise from other Promise, and such
copying would be dubious if either operand is a sub-class.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
coerceToLazy
(Object value) static Object
Forces the argument, if needed, to a non-Lazy value.static Object
If argument is Lazy, force it, unless already an instance of target.static Object
Forces the argument, if needed.getValue()
Return the actual value.final boolean
isBlank()
static <T> Promise
<T> static <T> Lazy
<T> makeBoundPromise
(T value) Wrap value as a forced Promise.void
void
print
(Appendable out) void
Bind promise to be an alias of another Lazy value.void
setException
(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
Bind this promise so forcing it evaluates the given procedure.void
Bind this promise to a given (eager) value.toString()
-
Constructor Details
-
Promise
public Promise()Create new "blank" Promise. Calling getValue just waits until one of setValue, setAlias, setException or setThunk is invoked. One of these is typically done by some other "producer" thread. -
Promise
Create a new Promise that will evaluate thunk when forced.
-
-
Method Details
-
setForceValueIfPromise
public void setForceValueIfPromise(boolean value) Set whether to recursively call getValue if getValue yields a Lazy value. -
makeBlank
-
makeBoundPromise
Wrap value as a forced Promise. -
coerceToLazy
-
getValue
Description copied from interface:Lazy
Return the actual value. Note thatgetValue()
may returnthis
, if this object isn't actually lazy. It may also return another lazy value. Normally you should usePromise.force{val}
to extra a non-lazy (eager) value. -
isBlank
public final boolean isBlank() -
checkBlank
public void checkBlank() -
setValue
Bind this promise to a given (eager) value. -
setAlias
Bind promise to be an alias of another Lazy value. -
setException
Bind this promise so forcing it throws the given exception. -
setThunk
Bind this promise so forcing it evaluates the given procedure. -
checkAlias
-
force1
Forces the argument, if needed. I.e. callsLazy.getValue()
once if the argument is Lazy. -
force
Forces the argument, if needed, to a non-Lazy value. I.e. callsLazy.getValue()
as many times as needed. -
force
If argument is Lazy, force it, unless already an instance of target. -
toString
-
print
- Specified by:
print
in interfacegnu.kawa.format.Printable
-
print
- Throws:
IOException
-