forked from functionaljava/functionaljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathF5Functions.java
More file actions
36 lines (31 loc) · 1.08 KB
/
Copy pathF5Functions.java
File metadata and controls
36 lines (31 loc) · 1.08 KB
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
30
31
32
33
34
35
36
package fj;
import fj.data.Validation;
/**
* Created by MarkPerry on 6/04/2014.
*/
public class F5Functions {
/**
* Promotes the TryCatch5 to a Validation that returns an Exception on the failure side and its result on the success side.
*
* @param t A TryCatch5 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, E, F, Z extends Exception> F5<A, B, C, D, E, Validation<Z, F>> toF5(final TryCatch5<A, B, C, D, E, F, Z> t) {
return (a, b, c, d, e) -> {
try {
return Validation.success(t.f(a, b, c, d, e));
} catch (Exception ex) {
return Validation.fail((Z) ex);
}
};
}
/**
* Partial application.
*
* @param a The <code>A</code> to which to apply this function.
* @return The function partially applied to the given argument.
*/
static public <A, B, C, D, E, F$> F4<B, C, D, E, F$> f(final F5<A, B, C, D, E, F$> f, final A a) {
return (b, c, d, e) -> f.f(a, b, c, d, e);
}
}