use of com.oath.cyclops.util.box.MutableShort in project cyclops by aol.
the class MutableShortTest method inClosure2.
@Test
public void inClosure2() {
MutableShort myInt = new MutableShort(zero);
BiFunction<Short, Short, MutableShort> fn = (i, j) -> myInt.set(new Short((short) (i * j)));
fn.apply(ten, twenty);
assertThat(myInt.getAsShort(), is((short) 200));
}
use of com.oath.cyclops.util.box.MutableShort in project cyclops by aol.
the class MutableShortTest method externalSet.
@Test
public void externalSet() {
value = 0;
MutableShort ext = MutableShort.fromExternal(() -> value, v -> this.value = v);
ext.set(ten);
assertThat(value, equalTo((short) 10));
}
use of com.oath.cyclops.util.box.MutableShort in project cyclops by aol.
the class MutableShortTest method testMutate.
@Test
public void testMutate() {
MutableShort num = MutableShort.of(twenty);
Stream.of(1, 2, 3, 4).map(i -> i * 10).peek(i -> num.mutate(n -> new Short((short) (n + i)))).forEach(System.out::println);
assertThat(num.getAsShort(), is((short) 120));
}
use of com.oath.cyclops.util.box.MutableShort in project cyclops by aol.
the class MutableShortTest method inClosure.
@Test
public void inClosure() {
MutableShort myInt = new MutableShort(zero);
Function<Integer, Function<Integer, MutableShort>> fn = ((Integer i) -> (Integer j) -> myInt.set(new Short((short) (i * j))));
fn.apply(10).apply(20);
assertThat(myInt.getAsShort(), is((short) 200));
}
use of com.oath.cyclops.util.box.MutableShort in project cyclops by aol.
the class MutableShortTest method externalGet.
@Test
public void externalGet() {
value = 100;
MutableShort ext = MutableShort.fromExternal(() -> value, v -> this.value = v);
assertThat(ext.get(), equalTo((short) 100));
}
Aggregations