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

fj.function.TryEffect0 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.Unit;
import fj.data.Option;

import static fj.Unit.unit;
import static fj.data.Option.none;
import static fj.data.Option.some;

public interface TryEffect0 {

	void f() throws Z;

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

	@SuppressWarnings("unchecked")
	default Try0 toTry0() {
		return () -> {
			try {
				f();
				return unit();
			} catch (Exception e) {
				throw ((Z) e);
			}
		};
	}

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

	default P1 toP1() {
		return P.lazy(() -> {
			toEffect0().f();
			return Unit.unit();
		});
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy