Nothing { @SuppressWarnings("WeakerAccess") public static <T> Function<T, Nothing> voidToNothing1(final @NotNull Consumer<? super T> consumer) { return input -> { consumer.accept(input); return Nothing.instance; }; } private  Nothing(); @SuppressWarnings("WeakerAccess") static Function<T, Nothing> voidToNothing1(final @NotNull Consumer<? super T> consumer); @SuppressWarnings("WeakerAccess") static BiFunction<T, U, Nothing> voidToNothing2(final @NotNull BiConsumer<? super T, ? super U> consumer); @SuppressWarnings("WeakerAccess") Nothing combine(final @Nullable Nothing nothing); static final Nothing instance; }
@Test public void testVoidToNothing1() throws Exception { final String sentinel = "sentinel"; final CompletableFuture<String> latch = new CompletableFuture<>(); final Consumer<String> consumer = latch::complete; final Nothing nothing = Nothing.voidToNothing1(consumer).apply(sentinel); assertTrue("future should be done: " + latch, latch.isDone()); assertSame("nothing should be returned", Nothing.instance, nothing); assertSame("latched should be same as input", sentinel, latch.get()); }