edu.rice.cs.plt.lambda
Class LazyThunk<R>

java.lang.Object
  extended by 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

Constructor Summary
LazyThunk(Thunk<? extends R> value)
           
 
Method Summary
 boolean isResolved()
          Test whether the thunk is in a "resolved" state.
static
<R> LazyThunk<R>
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
 

Constructor Detail

LazyThunk

public LazyThunk(Thunk<? extends R> value)
Method Detail

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)