Executes the supplier with the provided value and then rolls back to the previous local value. @param value value to be set. @param s supplier to be executed with the provided value. @return the result of the supplier.
(final T value, final Supplier<U> s)
| 180 | * @return the result of the supplier. |
| 181 | */ |
| 182 | public final <U> U let(final T value, final Supplier<U> s) { |
| 183 | final Optional<T> saved = get(); |
| 184 | set(Optional.of(value)); |
| 185 | try { |
| 186 | return s.get(); |
| 187 | } finally { |
| 188 | set(saved); |
| 189 | } |
| 190 | } |
| 191 | } |