edu.rice.cs.plt.lambda
Class LazyThunk<R>
java.lang.Object
edu.rice.cs.plt.lambda.LazyThunk<R>
- All Implemented Interfaces:
- ResolvingThunk<R>, Thunk<R>
public class LazyThunk<R>
- extends Object
- implements ResolvingThunk<R>
A thunk providing call-by-need evaluation of the nested thunk, value. The first invocation of
value() evaluates and discards the thunk; subsequent invocations return the same value as returned
previously. (If an exception occurs during evaluation, no result is cached and the nested thunk will be
evaluated again on a subsequent invocation.)
Evaluation is thread-safe: locking guarantees that the nested thunk will never be evaluated (and
terminate normally) twice. Thus, if two threads invoke value() simultaneously (and a result has not
yet been cached), one will block until the other resolves the nested thunk.
- See Also:
CachedThunk,
DelayedThunk,
LazyRunnable
|
Method Summary |
boolean |
isResolved()
Test whether the thunk is in a "resolved" state. |
static
|
make(Thunk<? extends R> value)
|
R |
value()
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
LazyThunk
public LazyThunk(Thunk<? extends R> value)
value
public R value()
- Specified by:
value in interface Thunk<R>
isResolved
public boolean isResolved()
- Description copied from interface:
ResolvingThunk
- Test whether the thunk is in a "resolved" state. If
true, an invocation of value
will return promptly and without exception.
- Specified by:
isResolved in interface ResolvingThunk<R>
make
public static <R> LazyThunk<R> make(Thunk<? extends R> value)