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

fj.function.Try0 Maven / Gradle / Ivy

Go to download

Functional Java is an open source library that supports closures for the Java programming language

The newest version!
package fj.function;

import fj.F0;
import fj.P;
import fj.P1;
import fj.data.Option;
import fj.data.Validation;

import static fj.data.Validation.fail;
import static fj.data.Validation.success;

/**
 * A product of A which may throw an Exception.
 *
 * Used to instantiate a lambda that may throw an Exception before converting to a P1.
 *
 * @see fj.Try#f(Try0)
 */

public interface Try0 {

    A f() throws Z;

    @SuppressWarnings("unchecked")
    default F0> toF0() {
        return () -> {
            try {
                return success(f());
            } catch (Exception e) {
                return fail((Z) e);
            }
        };
    }

    default TryEffect0 toTryEffect0() {
        return () -> f();
    }

    default Effect0 toEffect0() {
        return () -> {
            try {
                f();
            } catch (Exception e) {
            }
        };
    }

    default P1> toP1() {
        return P.lazy(() -> toF0().f());
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy