use of com.annimon.stream.function.IntBinaryOperator in project Lightweight-Stream-API by aNNiMON.
the class ReduceTest method testReduce.
@Test
public void testReduce() {
assertFalse(IntStream.empty().reduce(new IntBinaryOperator() {
@Override
public int applyAsInt(int left, int right) {
throw new IllegalStateException();
}
}).isPresent());
assertEquals(IntStream.of(42).reduce(new IntBinaryOperator() {
@Override
public int applyAsInt(int left, int right) {
throw new IllegalStateException();
}
}).getAsInt(), 42);
assertEquals(IntStream.of(41, 42).reduce(new IntBinaryOperator() {
@Override
public int applyAsInt(int left, int right) {
if (right > left)
return right;
return left;
}
}).getAsInt(), 42);
}
use of com.annimon.stream.function.IntBinaryOperator in project Lightweight-Stream-API by aNNiMON.
the class CustomTest method testCustomIntermediateOperator_Zip.
@Test
public void testCustomIntermediateOperator_Zip() {
final IntBinaryOperator op = new IntBinaryOperator() {
@Override
public int applyAsInt(int left, int right) {
return left + right;
}
};
IntStream s1 = IntStream.of(1, 3, 5, 7, 9);
IntStream s2 = IntStream.of(2, 4, 6, 8);
int[] expected = { 3, 7, 11, 15 };
IntStream result = s1.custom(new CustomOperators.Zip(s2, op));
assertThat(result.toArray(), is(expected));
}
Aggregations