forked from functionaljava/functionaljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathF3Functions.java
More file actions
29 lines (24 loc) · 792 Bytes
/
F3Functions.java
File metadata and controls
29 lines (24 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package fj;
import fj.data.Validation;
import static fj.data.Validation.fail;
import static fj.data.Validation.success;
/**
* Created by MarkPerry on 6/04/2014.
*/
public class F3Functions {
/**
* Promotes the TryCatch3 to a Validation that returns an Exception on the failure side and its result on the success side.
*
* @param t A TryCatch3 to promote
* @return A Validation with an Exception on the failure side and its result on the success side.
*/
static public <A, B, C, D> F3<A, B, C, Validation<Exception, D>> toF3(final TryCatch3<A, B, C, D> t) {
return (a, b, c) -> {
try {
return success(t.f(a, b, c));
} catch (Exception e) {
return fail(e);
}
};
}
}