Skip to content

Commit 62977fc

Browse files
committed
Moved Try type conversions to Try
1 parent 5d93466 commit 62977fc

File tree

13 files changed

+134
-171
lines changed

13 files changed

+134
-171
lines changed

core/src/main/java/fj/Effect.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ public static P1<Unit> f(Effect0 e) {
3131
* @return The function using the given effect.
3232
*/
3333
public static final <A> F<A, Unit> f(Effect1<A> e1) {
34-
return new F<A, Unit>() {
35-
public Unit f(final A a) {
34+
return a -> {
3635
e1.f(a);
3736
return unit();
38-
}
3937
};
4038
}
4139

core/src/main/java/fj/F1Functions.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -835,22 +835,6 @@ static public <A, B> ArrayList<B> mapJ(final F<A, B> f, final ArrayList<A> as) {
835835
return new ArrayList<B>(iterableStream(as).map(f).toCollection());
836836
}
837837

838-
/**
839-
* Promotes the TryCatch1 to a Validation that returns an Exception on the failure side and its result on the success side.
840-
*
841-
* @param t A TryCatch1 to promote
842-
* @return A Validation with an Exception on the failure side and its result on the success side.
843-
*/
844-
static public <A, B, E extends Exception> F<A, Validation<E, B>> toF1(final Try1<A, B, E> t) {
845-
return a -> {
846-
try {
847-
return Validation.success(t.f(a));
848-
} catch (Exception e) {
849-
return Validation.fail((E) e);
850-
}
851-
};
852-
}
853-
854838
static public <A, B, C> F<A, C> map(F<A, B> target, F<B, C> f) {
855839
return andThen(target, f);
856840
}

core/src/main/java/fj/F2Functions.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -347,23 +347,6 @@ public P3<Stream<Tree<C>>, C, Stream<Tree<C>>> f(final P3<Stream<Tree<A>>, A, St
347347
};
348348
}
349349

350-
351-
/**
352-
* Promotes the TryCatch2 to a Validation that returns an Exception on the failure side and its result on the success side.
353-
*
354-
* @param t A TryCatch2 to promote
355-
* @return A Validation with an Exception on the failure side and its result on the success side.
356-
*/
357-
static public <A, B, C, E extends Exception> F2<A, B, Validation<E, C>> toF2(final Try2<A, B, C, E> t) {
358-
return (a, b) -> {
359-
try {
360-
return Validation.success(t.f(a, b));
361-
} catch (Exception e) {
362-
return Validation.fail((E) e);
363-
}
364-
};
365-
}
366-
367350
static public <A, B, C, Z> F2<Z, B, C> contramapFirst(F2<A, B, C> target, F<Z, A> f) {
368351
return (z, b) -> target.f(f.f(z), b);
369352
}

core/src/main/java/fj/F3Functions.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,6 @@
1111
*/
1212
public class F3Functions {
1313

14-
/**
15-
* Promotes the TryCatch3 to a Validation that returns an Exception on the failure side and its result on the success side.
16-
*
17-
* @param t A TryCatch3 to promote
18-
* @return A Validation with an Exception on the failure side and its result on the success side.
19-
*/
20-
static public <A, B, C, D, E extends Exception> F3<A, B, C, Validation<E, D>> toF3(final Try3<A, B, C, D, E> t) {
21-
return (a, b, c) -> {
22-
try {
23-
return success(t.f(a, b, c));
24-
} catch (Exception e) {
25-
return fail((E) e);
26-
}
27-
};
28-
}
2914

3015
/**
3116
* Partial application.

core/src/main/java/fj/F4Functions.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,6 @@
88
*/
99
public class F4Functions {
1010

11-
12-
/**
13-
* Promotes the TryCatch4 to a Validation that returns an Exception on the failure side and its result on the success side.
14-
*
15-
* @param t A TryCatch4 to promote
16-
* @return A Validation with an Exception on the failure side and its result on the success side.
17-
*/
18-
static public <A, B, C, D, E, Z extends Exception> F4<A, B, C, D, Validation<Z, E>> toF4(final Try4<A, B, C, D, E, Z> t) {
19-
return (a, b, c, d) -> {
20-
try {
21-
return Validation.success(t.f(a, b, c, d));
22-
} catch (Exception ex) {
23-
return Validation.fail((Z) ex);
24-
}
25-
};
26-
}
27-
2811
/**
2912
* Partial application.
3013
*

core/src/main/java/fj/F5Functions.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@
88
*/
99
public class F5Functions {
1010

11-
/**
12-
* Promotes the TryCatch5 to a Validation that returns an Exception on the failure side and its result on the success side.
13-
*
14-
* @param t A TryCatch5 to promote
15-
* @return A Validation with an Exception on the failure side and its result on the success side.
16-
*/
17-
static public <A, B, C, D, E, F, Z extends Exception> F5<A, B, C, D, E, Validation<Z, F>> toF5(final Try5<A, B, C, D, E, F, Z> t) {
18-
return (a, b, c, d, e) -> {
19-
try {
20-
return Validation.success(t.f(a, b, c, d, e));
21-
} catch (Exception ex) {
22-
return Validation.fail((Z) ex);
23-
}
24-
};
25-
}
26-
2711
/**
2812
* Partial application.
2913
*

core/src/main/java/fj/F6Functions.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,6 @@
88
*/
99
public class F6Functions {
1010

11-
/**
12-
* Promotes the TryCatch6 to a Validation that returns an Exception on the failure side and its result on the success side.
13-
*
14-
* @param t A TryCatch6 to promote
15-
* @return A Validation with an Exception on the failure side and its result on the success side.
16-
*/
17-
static public <A, B, C, D, E, F, G, Z extends Exception> F6<A, B, C, D, E, F, Validation<Z, G>> toF6(final Try6<A, B, C, D, E, F, G, Z> t) {
18-
return (a, b, c, d, e, f) -> {
19-
try {
20-
return Validation.success(t.f(a, b, c, d, e, f));
21-
} catch (Exception ex) {
22-
return Validation.fail((Z) ex);
23-
}
24-
};
25-
}
26-
27-
2811
/**
2912
* Partial application.
3013
*

core/src/main/java/fj/F7Functions.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@
88
*/
99
public class F7Functions {
1010

11-
/**
12-
* Promotes the TryCatch7 to a Validation that returns an Exception on the failure side and its result on the success side.
13-
*
14-
* @param t A TryCatch7 to promote
15-
* @return A Validation with an Exception on the failure side and its result on the success side.
16-
*/
17-
static public <A, B, C, D, E, F, G, H, Z extends Exception> F7<A, B, C, D, E, F, G, Validation<Z, H>> toF7(final Try7<A, B, C, D, E, F, G, H, Z> t) {
18-
return (a, b, c, d, e, f, g) -> {
19-
try {
20-
return Validation.success(t.f(a, b, c, d, e, f, g));
21-
} catch (Exception ex) {
22-
return Validation.fail((Z) ex);
23-
}
24-
};
25-
}
26-
2711
/**
2812
* Partial application.
2913
*

core/src/main/java/fj/F8Functions.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@
88
*/
99
public class F8Functions {
1010

11-
/**
12-
* Promotes the TryCatch8 to a Validation that returns an Exception on the failure side and its result on the success side.
13-
*
14-
* @param t A TryCatch8 to promote
15-
* @return A Validation with an Exception on the failure side and its result on the success side.
16-
*/
17-
static public <A, B, C, D, E, F, G, H, I, Z extends Exception> F8<A, B, C, D, E, F, G, H, Validation<Z, I>> toF8(final Try8<A, B, C, D, E, F, G, H, I, Z> t) {
18-
return (a, b, c, d, e, f, g, h) -> {
19-
try {
20-
return Validation.success(t.f(a, b, c, d, e, f, g, h));
21-
} catch (Exception ex) {
22-
return Validation.fail((Z) ex);
23-
}
24-
};
25-
}
26-
2711
/**
2812
* Partial application.
2913
*

core/src/main/java/fj/P1.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -232,22 +232,6 @@ public A f(final B b) {
232232
};
233233
}
234234

235-
/**
236-
* Promotes the TryCatch0 to a Validation that returns an Exception on the failure side and its result on the success side.
237-
*
238-
* @param t A TryCatch0 to promote
239-
* @return A Validation with an Exception on the failure side and its result on the success side.
240-
*/
241-
static public <A, E extends Exception> P1<Validation<E, A>> toP1(final Try0<A, E> t) {
242-
return P.lazy(u -> {
243-
try {
244-
return Validation.success(t.f());
245-
} catch (Exception e) {
246-
return Validation.fail((E) e);
247-
}
248-
});
249-
}
250-
251235
public String toString() {
252236
return Show.p1Show(Show.<A>anyShow()).showS(this);
253237
}

0 commit comments

Comments
 (0)