/** * @param varFn New value * @return this object with mutated value */ public Mutable<T> mutate(final Function<T, T> varFn) { return set(varFn.apply(get())); }
@Test public void testClosedVar() { assertThat(new Mutable(10).get(),equalTo(10)); } @Test
@Test public void inClosure2(){ Mutable<Integer> myInt = new Mutable<>(0); BiFunction<Integer,Integer,Mutable<Integer>> fn = (i,j)-> myInt.set(i*j); fn.apply(10,20); assertThat(myInt.get(), is(200)); }
@Test public void externalMapOutputToObj(){ value = 20; Mutable<Integer> ext = MutableByte.fromExternal(()->value,v->this.value=v) .mapOutputToObj(s->s*2); assertThat(ext.get(),equalTo(40)); }
@Test public void externalMapOutputToObj(){ value = 200; Mutable<Integer> ext = MutableChar.fromExternal(()->value,v->this.value=v) .mapOutputToObj(s->s*2); assertThat(ext.get(),equalTo(400)); }
@Test public void testPeek() { Mutable<Integer> capture = Mutable.of(null); just = just.peek(c->capture.set(c)); assertThat(capture.get(),equalTo(10)); }
@Test public void testPeek() { Mutable<Integer> capture = Mutable.of(null); just = just.peek(c->capture.set(c)); assertThat(capture.get(),equalTo(10)); }
@Test public void testPeek() { Mutable<Integer> capture = Mutable.of(null); just = just.peek(c->capture.set(c)); just.get(); assertThat(capture.get(),equalTo(10)); }
@Test public void testPeek() { Mutable<Integer> capture = Mutable.of(null); just = just.peek(c->capture.set(c)); just.get(); assertThat(capture.get(),equalTo(10)); }
@Test public void testPeek() { Mutable<Integer> capture = Mutable.of(null); just = just.peek(c->capture.set(c)); just.get(); assertThat(capture.get(),equalTo(10)); }
@Test public void testPeek() { Mutable<Integer> capture = Mutable.of(null); just = just.peek(c->capture.set(c)); just.get(); assertThat(capture.get(),equalTo(10)); }