T
- public class LazyImmutable<T> extends java.lang.Object implements java.util.function.Supplier<T>, java.util.function.Consumer<T>, Matchable.ValueAndOptionalMatcher<T>, Functor<T>, Applicativable<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).Applicativable.Applicatives, Applicativable.SemigroupApplyer<T>
Value.ValueImpl<T>
Matchable.AsMatchable, Matchable.AutoCloseableMatchableIterable<TYPE>, Matchable.CheckValue1<T,R>, Matchable.CheckValue2<T1,T2,R>, Matchable.CheckValue3<T1,T2,T3,R>, Matchable.CheckValue4<T1,T2,T3,T4,R>, Matchable.CheckValue5<T1,T2,T3,T4,T5,R>, Matchable.CheckValueOpt<T,R>, Matchable.CheckValues<T,R>, Matchable.MatchableIterable<TYPE>, Matchable.MatchableObject<TYPE>, Matchable.MatchableOptional<T>, Matchable.MatchSelf<TYPE>, Matchable.MTuple1<T1>, Matchable.MTuple2<T1,T2>, Matchable.MTuple3<T1,T2,T3>, Matchable.MTuple4<T1,T2,T3,T4>, Matchable.MTuple5<T1,T2,T3,T4,T5>, Matchable.MXor<T1,T2>, Matchable.ValueAndOptionalMatcher<T>
Convertable.SupplierToConvertable<T>
Constructor and Description |
---|
LazyImmutable() |
Modifier and Type | Method and Description |
---|---|
void |
accept(T t) |
<U> LazyImmutable<U> |
cast(java.lang.Class<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)
Create a new matchable that will match on the fields of the provided Object
|
<R> LazyImmutable<R> |
patternMatch(java.util.function.Function<Matchable.CheckValues<T,R>,Matchable.CheckValues<T,R>> case1,
java.util.function.Supplier<? extends R> otherwise)
Transform the elements of this Stream with a Pattern Matching case and default value
|
LazyImmutable<T> |
peek(java.util.function.Consumer<? super T> c) |
LazyImmutable<T> |
setOnce(T val)
Set the value of this ImmutableClosedValue
If it has already been set will throw an exception
|
ReactiveSeq<T> |
stream() |
LazyImmutable<T> |
toLazyImmutable() |
<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)
|
<T> Unit<T> |
unit(T unit) |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
toOptional, visit
matches
ap, ap, ap1, ap2, ap3, ap4, ap5
convertTo, convertToAsync, fold, fold, generate, getMatchable, iterate, mapReduce, mkString, newSubscriber, subscribe, test, toDequeX, toEvalAlways, toEvalLater, toEvalNow, toFutureStream, toFutureStream, toIor, toListX, toMaybe, toMutable, toPBagX, toPOrderedSetX, toPQueueX, toPSetX, toPStackX, toPVectorX, toQueueX, toSetX, toSimpleReact, toSimpleReact, toSortedSetX, toTry, toTry, toXor, unapply
foldRight, foldRight, foldRight, foldRightMapToType, join, join, join, mapReduce, print, print, printErr, printOut, reduce, reduce, reduce, reduce, reduce, reduce, reduce
from, from, from, from, from, from, from, from, from, from, fromCharSequence, fromIterable, fromOptional, listOfValues, ofDecomposable, otherwise, otherwise, then, then, when, when, when, when, when, when, when, when, when, when, whenGuard, whenTrue, whenValues
fromSupplier, orElse, orElseGet, orElseThrow, toAtomicReference, toCompletableFuture, toCompletableFutureAsync, toCompletableFutureAsync, toFutureW, toList, toOptionalAtomicReference, toStream
public T get()
get
in interface Convertable<T>
get
in interface java.util.function.Supplier<T>
public static <T> LazyImmutable<T> unbound()
public static <T> LazyImmutable<T> of(T value)
Matchable
public static <T> LazyImmutable<T> def()
public <R> LazyImmutable<R> map(java.util.function.Function<? super T,? extends R> fn)
public <R> LazyImmutable<R> patternMatch(java.util.function.Function<Matchable.CheckValues<T,R>,Matchable.CheckValues<T,R>> case1, java.util.function.Supplier<? extends R> otherwise)
Functor
List<String> result = CollectionX.of(1,2,3,4)
.patternMatch(
c->c.valuesWhere(i->"even", (Integer i)->i%2==0 )
)
// CollectionX["odd","even","odd","even"]
patternMatch
in interface Functor<T>
case1
- Function to generate a case (or chain of cases as a single case)otherwise
- Value if supplied case doesn't matchpublic <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 Matchable.MatchableOptional<T>
iterator
in interface Matchable.ValueAndOptionalMatcher<T>
iterator
in interface Convertable<T>
iterator
in interface java.lang.Iterable<T>
public LazyImmutable<T> toLazyImmutable()
toLazyImmutable
in interface Value<T>
public <U> LazyImmutable<U> cast(java.lang.Class<U> type)
Functor
ClassCastException
.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)public LazyImmutable<T> peek(java.util.function.Consumer<? super T> c)
public <R> LazyImmutable<R> trampoline(java.util.function.Function<? super T,? extends Trampoline<? extends R>> mapper)
Functor
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 Functor<T>
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object