Skip to content

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

screen shot 2016-02-22 at 8 44 42 pm

Mutable

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

Examples

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!"
Clone this wiki locally