T - Type held inside closed varpublic class MutableLong extends java.lang.Object implements java.util.function.LongSupplier, java.util.function.LongConsumer, Matchable.ValueAndOptionalMatcher<java.lang.Long>
String var = "hello";
Runnable r = () -> var ="world";
Won't compile because var is treated as if it is final.
This can be 'worked around' by using a wrapping object or array.
e.g.
Mutable<String> var = Mutable.of("hello");
Runnable r = () -> var.set("world");
Value.ValueImpl<T>Convertable.SupplierToConvertable<T>| Constructor and Description |
|---|
MutableLong() |
| Modifier and Type | Method and Description |
|---|---|
void |
accept(long value) |
static MutableLong |
fromExternal(java.util.function.LongSupplier s,
java.util.function.LongConsumer c)
Construct a MutableLong that gets and sets an external value using the provided Supplier and Consumer
e.g.
|
java.lang.Long |
get() |
long |
getAsLong() |
MutableLong |
mapInput(java.util.function.LongUnaryOperator fn)
Use the supplied function to perform a lazy map operation when get is called
|
<T1> Mutable<T1> |
mapInputToObj(java.util.function.Function<T1,java.lang.Long> fn)
Use the supplied function to perform a lazy map operation when get is called
|
MutableLong |
mapOutput(java.util.function.LongUnaryOperator fn)
Use the supplied function to perform a lazy map operation when get is called
|
<R> Mutable<R> |
mapOutputToObj(java.util.function.Function<java.lang.Long,R> fn)
Use the supplied function to perform a lazy map operation when get is called
|
MutableLong |
mutate(java.util.function.LongFunction<java.lang.Long> varFn) |
static MutableLong |
of(long var)
Create a Mutable variable, which can be mutated inside a Closure
e.g.
|
MutableLong |
set(long var) |
java.util.stream.LongStream |
toLongStream() |
java.util.OptionalLong |
toOptionalLong() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waititerator, toOptional, visitmatchescollect, fold, fold, generate, iterate, mapReduce, mkString, newSubscriber, of, stream, subscribe, test, toDequeX, toEvalAlways, toEvalLater, toEvalNow, toFeatureToggle, toFutureStream, toFutureStream, toIor, toLazyImmutable, toList, toListX, toMaybe, toMutable, toPBagX, toPOrderedSetX, toPQueueX, toPSetX, toPStackX, toPVectorX, toQueueX, toSetX, toSimpleReact, toSimpleReact, toSortedSetX, toTry, toTry, toTry, toXor, toXor, unapplyendsWith, endsWithIterable, findAny, findFirst, firstValue, foldable, foldRight, foldRight, foldRight, foldRightMapToType, get, groupBy, join, join, join, mapReduce, print, print, printErr, printOut, reduce, reduce, reduce, reduce, reduce, reduce, reduce, schedule, scheduleFixedDelay, scheduleFixedRate, single, single, singleOptional, startsWith, startsWithIterable, toConcurrentLazyCollection, toConcurrentLazyStreamable, toLazyCollection, validate, xMatchcollect, fromSupplier, isPresent, orElse, orElseGet, orElseThrow, toAtomicReference, toCompletableFuture, toCompletableFutureAsync, toCompletableFutureAsync, toFutureW, toFutureWAsync, toFutureWAsync, toOptionalAtomicReference, toStreampublic static MutableLong of(long var)
Mutable<Integer> num = Mutable.of(20);
Stream.of(1,2,3,4).map(i->i*10).peek(i-> num.mutate(n->n+i)).foreach(System.out::println);
System.out.println(num.get());
//prints 120
var - Initial value of Mutablepublic static MutableLong fromExternal(java.util.function.LongSupplier s, java.util.function.LongConsumer c)
MutableLong mutable = MutableLong.fromExternal(()->!this.value,val->!this.value);
s - Supplier of an external valuec - Consumer that sets an external valuepublic <R> Mutable<R> mapOutputToObj(java.util.function.Function<java.lang.Long,R> fn)
MutableLong mutable = MutableLong.fromExternal(()->!this.value,val->!this.value);
Mutable<Long> withOverride = mutable.mapOutputToObj(b->{
if(override)
return 10.0;
return b;
});
fn - Map function to be applied to the result when get is calledpublic <T1> Mutable<T1> mapInputToObj(java.util.function.Function<T1,java.lang.Long> fn)
MutableLong mutable = MutableLong.fromExternal(()->!this.value,val->!this.value);
Mutable<Long> withOverride = mutable.mapInputToObj(b->{
if(override)
return 10.0;
return b;
});
fn - Map function to be applied to the input when set is calledpublic MutableLong mapOutput(java.util.function.LongUnaryOperator fn)
MutableLong mutable = MutableLong.fromExternal(()->!this.value,val->!this.value);
MutableLong withOverride = mutable.mapOutput(b->{
if(override)
return 10.0;
return b;
});
fn - Map function to be applied to the result when get is calledpublic MutableLong mapInput(java.util.function.LongUnaryOperator fn)
MutableLong mutable = MutableLong.fromExternal(()->!this.value,val->!this.value);
MutableLong withOverride = mutable.mapInput(b->{
if(override)
return 10.0;
return b;
});
fn - Map function to be applied to the input when set is calledpublic long getAsLong()
getAsLong in interface java.util.function.LongSupplierpublic MutableLong set(long var)
var - New valuepublic MutableLong mutate(java.util.function.LongFunction<java.lang.Long> varFn)
varFn - New valuepublic java.util.OptionalLong toOptionalLong()
public java.util.stream.LongStream toLongStream()
public java.lang.Long get()
get in interface Convertable<java.lang.Long>get in interface java.util.function.Supplier<java.lang.Long>public void accept(long value)
accept in interface java.util.function.LongConsumer