Search in sources :

Example 1 with LongBinaryOperator

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));
}
Also used : LongBinaryOperator(com.annimon.stream.function.LongBinaryOperator) LongStream(com.annimon.stream.LongStream) CustomOperators(com.annimon.stream.CustomOperators) Test(org.junit.Test)

Example 2 with LongBinaryOperator

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));
}
Also used : LongBinaryOperator(com.annimon.stream.function.LongBinaryOperator) Test(org.junit.Test)

Example 3 with LongBinaryOperator

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));
}
Also used : LongBinaryOperator(com.annimon.stream.function.LongBinaryOperator) Test(org.junit.Test)

Aggregations

LongBinaryOperator (com.annimon.stream.function.LongBinaryOperator)3 Test (org.junit.Test)3 CustomOperators (com.annimon.stream.CustomOperators)1 LongStream (com.annimon.stream.LongStream)1