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

net.cassite.f.While Maven / Gradle / Ivy

The newest version!
package net.cassite.f;

import io.vertx.core.Future;
import org.jetbrains.annotations.NotNull;

import java.util.function.BooleanSupplier;
import java.util.function.Supplier;

public class While {
    private While() {
    }

    public static WhileLoop cond(@NotNull Supplier> condition) {
        if (condition == null)
            throw new NullPointerException();
        return new WhileLoop(condition);
    }

    public static WhileLoop cond(@NotNull BooleanSupplier condition) {
        if (condition == null)
            throw new NullPointerException();
        return cond(() -> F.unit(condition.getAsBoolean()));
    }

    public static class WhileLoop {
        private final Supplier> condition;

        WhileLoop(Supplier> condition) {
            this.condition = condition;
        }

        public  Monad> yield(@NotNull Supplier> func) {
            if (func == null)
                throw new NullPointerException();
            return For.init(null).cond(c -> condition.get()).incrSync(c -> {
            }).yield(c -> func.get());
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy