T - public class LazyImmutable<T>
extends java.lang.Object
implements java.util.function.Supplier<T>
public static <T> Supplier<T> memoiseSupplier(Supplier<T> s){
LazyImmutable<T> lazy = LazyImmutable.def();
return () -> lazy.computeIfAbsent(s);
}
Has map and flatMap methods, but is not a Monad (see example usage above for why, it is the initial mutation that is valuable).| Constructor and Description |
|---|
LazyImmutable() |
| Modifier and Type | Method and Description |
|---|---|
T |
computeIfAbsent(java.util.function.Supplier<T> lazy)
Get the current value or set if it has not been set yet
|
static <T> LazyImmutable<T> |
def() |
<R> LazyImmutable<R> |
flatMap(java.util.function.Function<T,LazyImmutable<R>> fn)
FlatMap the value stored in Immutable Closed Value from one Value to another
If this is an unitiatilised ImmutableClosedValue, an uninitialised closed value will be returned instead
|
T |
get() |
<R> LazyImmutable<R> |
map(java.util.function.Function<T,R> fn)
Map the value stored in this Immutable Closed Value from one Value to another
If this is an unitiatilised ImmutableClosedValue, an uninitialised closed value will be returned instead
|
static <T> LazyImmutable<T> |
of(T value) |
LazyImmutable<T> |
setOnce(T val)
Set the value of this ImmutableClosedValue
If it has already been set will throw an exception
|
static <T> LazyImmutable<T> |
unbound()
Create an intermediate unbound (or unitialised) ImmutableClosedValue)
|
public T get()
get in interface java.util.function.Supplier<T>public static <T> LazyImmutable<T> unbound()
public static <T> LazyImmutable<T> of(T value)
value - Create an initialised ImmutableClosedValue with specified valuepublic static <T> LazyImmutable<T> def()
public <R> LazyImmutable<R> map(java.util.function.Function<T,R> fn)
fn - Mapper functionpublic <R> LazyImmutable<R> flatMap(java.util.function.Function<T,LazyImmutable<R>> fn)
fn - Flat Mapper functionpublic LazyImmutable<T> setOnce(T val) throws LazyImmutableSetMoreThanOnceException
val - Value to set toLazyImmutableSetMoreThanOnceException