File tree Expand file tree Collapse file tree
src/main/java/de/variantsync/evolution/util/functional Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -86,6 +86,27 @@ public A run() {
8686 return val ;
8787 }
8888
89+ /**
90+ * Run the lazy computation, obtain the result, and immediately forget it.
91+ * This method first calls {@link #run()} and then {@link #forget()}.
92+ * @return The result of this lazy computation.
93+ */
94+ public A take () {
95+ final A result = run ();
96+ forget ();
97+ return result ;
98+ }
99+
100+ /**
101+ * Clears the cached value, such that it has to be recomputed next time it is queried.
102+ * @return True if a value was cleared. False if there was no cached value to forget.
103+ */
104+ public boolean forget () {
105+ final boolean aValueWasForgotten = val != null ;
106+ val = null ;
107+ return aValueWasForgotten ;
108+ }
109+
89110 /**
90111 * Lazy is a functor.
91112 * @param f Function to apply to the result of this Lazy when it is computed.
You can’t perform that action at this time.
0 commit comments