/** * Zips the value of this Perhaps with the other Perhaps through * a BiFunction. * @param <U> the value type of the other source * @param <R> the result type * @param other the other Perhaps source * @param zipper the function receiving each source value and should * return a value to be emitted * @return the new Perhaps instance */ @SuppressWarnings("unchecked") public final <U, R> Perhaps<R> zipWith(Perhaps<? extends U> other, BiFunction<? super T, ? super U, ? extends R> zipper) { ObjectHelper.requireNonNull(other, "other is null"); ObjectHelper.requireNonNull(zipper, "zipper is null"); return zipArray(Functions.toFunction(zipper), this, other); }
/** * Zips the value of this Perhaps with the other Perhaps through * a BiFunction. * @param <U> the value type of the other source * @param <R> the result type * @param other the other Perhaps source * @param zipper the function receiving each source value and should * return a value to be emitted * @return the new Perhaps instance */ @SuppressWarnings("unchecked") public final <U, R> Perhaps<R> zipWith(Perhaps<? extends U> other, BiFunction<? super T, ? super U, ? extends R> zipper) { ObjectHelper.requireNonNull(other, "other is null"); ObjectHelper.requireNonNull(zipper, "zipper is null"); return zipArray(Functions.toFunction(zipper), this, other); }
@SuppressWarnings("unchecked") @Test public void zipArrayError1() { Perhaps.zipArray(new Function<Object[], Object>() { @Override public Object apply(Object[] a) throws Exception { return "" + a[0] + a[1]; } }, Perhaps.error(new IOException()), Perhaps.just(2)) .test() .assertFailure(IOException.class); }
@SuppressWarnings("unchecked") @Test public void zipArrayError2() { Perhaps.zipArray(new Function<Object[], Object>() { @Override public Object apply(Object[] a) throws Exception { return "" + a[0] + a[1]; } }, Perhaps.just(1), Perhaps.error(new IOException())) .test() .assertFailure(IOException.class); }
@SuppressWarnings("unchecked") @Test public void zipArray() { Perhaps.zipArray(new Function<Object[], Object>() { @Override public Object apply(Object[] a) throws Exception { return "" + a[0] + a[1]; } }, Perhaps.just(1), Perhaps.just(2)) .test() .assertResult("12"); }