All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.adamcin.oakpal.core.Nothing Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
package net.adamcin.oakpal.core;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;

/**
 * A sentinel type for functional parameters representing Nothing, like Void.
 */
public final class Nothing {
    /**
     * This is the singleton sentinel value.
     */
    public static final Nothing instance = new Nothing();

    private Nothing() {
        /* prevent instantiation */
    }

    @SuppressWarnings("WeakerAccess")
    public static  Function
    voidToNothing1(final @NotNull Consumer consumer) {
        return input -> {
            consumer.accept(input);
            return Nothing.instance;
        };
    }

    @SuppressWarnings("WeakerAccess")
    public static  BiFunction
    voidToNothing2(final @NotNull BiConsumer consumer) {
        return (inputT, inputU) -> {
            consumer.accept(inputT, inputU);
            return Nothing.instance;
        };
    }

    @SuppressWarnings("WeakerAccess")
    public Nothing combine(final @Nullable Nothing nothing) {
        return this;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy