T
- public class LazyImmutable<T> extends java.lang.Object implements To<LazyImmutable<T>>, java.util.function.Supplier<T>, java.util.function.Consumer<T>, Transformable<T>, Zippable<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 |
---|---|
void |
accept(T t) |
<U> LazyImmutable<U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException . |
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() |
boolean |
equals(java.lang.Object obj) |
<R> LazyImmutable<? extends R> |
flatMap(java.util.function.Function<? super T,? extends LazyImmutable<? extends 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() |
int |
hashCode() |
boolean |
isSet() |
java.util.Iterator<T> |
iterator() |
<R> LazyImmutable<R> |
map(java.util.function.Function<? super T,? extends 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> |
peek(java.util.function.Consumer<? super T> c)
Peek at the current value of this Transformable, without transforming it
|
LazyImmutable<T> |
setOnce(T val)
Set the value of this ImmutableClosedValue
If it has already been set will throw an exception
|
ReactiveSeq<T> |
stream() |
<R> LazyImmutable<R> |
trampoline(java.util.function.Function<? super T,? extends Trampoline<? extends R>> mapper)
Performs a map operation that can call a recursive method without running out of stack space
|
static <T> LazyImmutable<T> |
unbound()
Create an intermediate unbound (or unitialised) ImmutableClosedValue)
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
zip, zip, zip, zip3, zip3, zip4, zip4, zipP, zipP, zipS, zipS, zipWith, zipWithP, zipWithS
retry, retry
futureStream, getStreamable, isEmpty, jdkStream, reactiveSeq, reveresedJDKStream, reveresedStream
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<? super T,? extends R> fn)
map
in interface Transformable<T>
fn
- Mapper functionpublic <R> LazyImmutable<? extends R> flatMap(java.util.function.Function<? super T,? extends LazyImmutable<? extends R>> fn)
fn
- Flat Mapper functionpublic LazyImmutable<T> setOnce(T val)
val
- Value to set topublic T computeIfAbsent(java.util.function.Supplier<T> lazy)
lazy
- Supplier to generate new valuepublic boolean isSet()
public ReactiveSeq<T> stream()
public java.util.Iterator<T> iterator()
iterator
in interface java.lang.Iterable<T>
public <U> LazyImmutable<U> cast(java.lang.Class<? extends U> type)
Transformable
ClassCastException
.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)cast
in interface Transformable<T>
public LazyImmutable<T> peek(java.util.function.Consumer<? super T> c)
Transformable
of(1,2,3).map(System.out::println)
1
2
3
peek
in interface Transformable<T>
c
- Consumer that recieves each element from this Transformablepublic <R> LazyImmutable<R> trampoline(java.util.function.Function<? super T,? extends Trampoline<? extends R>> mapper)
Transformable
ReactiveSeq.of(10,20,30,40)
.trampoline(i-> fibonacci(i))
.forEach(System.out::println);
Trampoline<Long> fibonacci(int i){
return fibonacci(i,1,0);
}
Trampoline<Long> fibonacci(int n, long a, long b) {
return n == 0 ? Trampoline.done(b) : Trampoline.more( ()->fibonacci(n-1, a+b, a));
}
55
6765
832040
102334155
ReactiveSeq.of(10_000,200_000,3_000_000,40_000_000)
.trampoline(i-> fibonacci(i))
.forEach(System.out::println);
completes successfully
trampoline
in interface Transformable<T>
mapper
- TCO Transformation functionpublic int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object