-
Notifications
You must be signed in to change notification settings - Fork 51
cyclops closures : Mutable for managing and mutating mutable variables
johnmcclean-aol edited this page Nov 21, 2016
·
3 revisions
Cyclops has merged with simple-react. Please update your bookmarks (stars :) ) to https://github.com/aol/cyclops-react
Mutable provides a wrapper over a mutable variable, it implements Convertable which allows the value to be converted into various forms (such as a thread-safe AtomicReference, Optional, Stream, CompletableFuture etc).
The mutable family support working with Objects or Java primitives
- Mutable
- MutableInt
- MutableDouble
- MutableLong
- MutableFloat
- MutableShort
- MutableByte
- MutableChar
- MutableBoolean
Mutable<String> var = Mutable.of("hello");
Runnable r = () -> var.set("world");
String value = "world";
Mutable<String> ext = Mutable.fromExternal(()->value,v->this.value=v);
ext.set("hello");
MutableFloat myFloat = new MutableFloat(zero);
Function<Integer,Function<Integer,MutableFloat>> fn = ((Integer i)-> (Integer j)-> myFloatset(new Float((float)(i*j))));
fn.apply(10).apply(20);
//myFloat 200
Mutable<String> ext = Mutable.fromExternal(()->value,v->this.value=v)
.mapInput(s->s+"!");
ext.set("hello");
//value == "hello!"