T
- Type held inside closed varpublic class Mutable<T> extends java.lang.Object implements java.util.function.Supplier<T>, java.util.function.Consumer<T>, Matchable.ValueAndOptionalMatcher<T>
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>
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 |
---|
Mutable() |
Modifier and Type | Method and Description |
---|---|
void |
accept(T t) |
static <T> Mutable<T> |
fromExternal(java.util.function.Supplier<T> s,
java.util.function.Consumer<T> c)
Construct a Mutable that gets and sets an external value using the provided Supplier and Consumer
e.g.
|
T |
get() |
<T1> Mutable<T1> |
mapInput(java.util.function.Function<T1,T> fn) |
<R> Mutable<R> |
mapOutput(java.util.function.Function<T,R> fn) |
Mutable<T> |
mutate(java.util.function.Function<T,T> varFn) |
static <T> Mutable<T> |
of(T var)
Create a Mutable variable, which can be mutated inside a Closure
e.g.
|
Mutable<T> |
set(T var) |
Mutable<T> |
toMutable() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
iterator, toOptional, visit
matches
convertTo, convertToAsync, fold, fold, generate, getMatchable, iterate, mapReduce, mkString, newSubscriber, stream, subscribe, test, toDequeX, toEvalAlways, toEvalLater, toEvalNow, toFutureStream, toFutureStream, toIor, toLazyImmutable, toListX, toMaybe, 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 static <T> Mutable<T> of(T 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
public static <T> Mutable<T> fromExternal(java.util.function.Supplier<T> s, java.util.function.Consumer<T> c)
Mutable<Integer> mutable = Mutable.from(()->this.value*2,val->this.value=val);
s
- Supplier of an external valuec
- Consumer that sets an external valuepublic T get()
get
in interface Convertable<T>
get
in interface java.util.function.Supplier<T>
public Mutable<T> set(T var)
var
- New valuepublic Mutable<T> mutate(java.util.function.Function<T,T> varFn)
varFn
- New value