use of com.annimon.stream.function.LongBinaryOperator in project Lightweight-Stream-API by aNNiMON.
the class CustomTest method testCustomLongermediateOperator_Zip.
@Test
public void testCustomLongermediateOperator_Zip() {
final LongBinaryOperator op = new LongBinaryOperator() {
@Override
public long applyAsLong(long left, long right) {
return left + right;
}
};
LongStream s1 = LongStream.of(1, 3, 5, 7, 9);
LongStream s2 = LongStream.of(2, 4, 6, 8);
long[] expected = { 3, 7, 11, 15 };
LongStream result = s1.custom(new CustomOperators.ZipLong(s2, op));
assertThat(result.toArray(), is(expected));
}
use of com.annimon.stream.function.LongBinaryOperator in project Lightweight-Stream-API by aNNiMON.
the class ReduceTest method testReduceWithIdentityOnEmptyStream.
@Test
public void testReduceWithIdentityOnEmptyStream() {
long result = LongStream.empty().reduce(1234567L, new LongBinaryOperator() {
@Override
public long applyAsLong(long left, long right) {
return left + right;
}
});
assertThat(result, is(1234567L));
}
use of com.annimon.stream.function.LongBinaryOperator in project Lightweight-Stream-API by aNNiMON.
the class ReduceTest method testReduceWithIdentity.
@Test
public void testReduceWithIdentity() {
long result = LongStream.of(12, -3772, 3039, 19840, 100000).reduce(0L, new LongBinaryOperator() {
@Override
public long applyAsLong(long left, long right) {
return left + right;
}
});
assertThat(result, is(119119L));
}
Aggregations