fj.TryEffect Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of functionaljava Show documentation
Show all versions of functionaljava Show documentation
Functional Java is an open source library that supports closures for the Java programming language
package fj;
import fj.data.Validation;
import fj.function.*;
/**
* Created by mperry on 29/08/2014.
*/
public final class TryEffect {
private TryEffect(){}
@SuppressWarnings("unchecked")
public static P1> f(TryEffect0 t) {
return P.lazy(() -> {
try {
t.f();
return Validation.success(Unit.unit());
} catch (Exception e) {
return Validation.fail((Z) e);
}
});
}
@SuppressWarnings("unchecked")
public static F> f(TryEffect1 t) {
return a -> {
try {
t.f(a);
return Validation.success(Unit.unit());
} catch (Exception e) {
return Validation.fail((Z) e);
}
};
}
@SuppressWarnings("unchecked")
public static F2> f(TryEffect2 t) {
return (a, b) -> {
try {
t.f(a, b);
return Validation.success(Unit.unit());
} catch (Exception e) {
return Validation.fail((Z) e);
}
};
}
@SuppressWarnings("unchecked")
public static F3> f(TryEffect3 t) {
return (a, b, c) -> {
try {
t.f(a, b, c);
return Validation.success(Unit.unit());
} catch (Exception e) {
return Validation.fail((Z) e);
}
};
}
@SuppressWarnings("unchecked")
public static F4> f(TryEffect4 t) {
return (a, b, c, d) -> {
try {
t.f(a, b, c, d);
return Validation.success(Unit.unit());
} catch (Exception e) {
return Validation.fail((Z) e);
}
};
}
@SuppressWarnings("unchecked")
public static F5> f(TryEffect5 t) {
return (a, b, c, d, e) -> {
try {
t.f(a, b, c, d, e);
return Validation.success(Unit.unit());
} catch (Exception z) {
return Validation.fail((Z) z);
}
};
}
@SuppressWarnings("unchecked")
public static F6> f(TryEffect6 t) {
return (a, b, c, d, e, f) -> {
try {
t.f(a, b, c, d, e, f);
return Validation.success(Unit.unit());
} catch (Exception z) {
return Validation.fail((Z) z);
}
};
}
@SuppressWarnings("unchecked")
public static F7> f(TryEffect7 t) {
return (a, b, c, d, e, f, g) -> {
try {
t.f(a, b, c, d, e, f, g);
return Validation.success(Unit.unit());
} catch (Exception z) {
return Validation.fail((Z) z);
}
};
}
@SuppressWarnings("unchecked")
public static F8> f(TryEffect8 t) {
return (a, b, c, d, e, f, g, h) -> {
try {
t.f(a, b, c, d, e, f, g, h);
return Validation.success(Unit.unit());
} catch (Exception z) {
return Validation.fail((Z) z);
}
};
}
}