Skip to content

Commit e128256

Browse files
committed
Added conversion from io to P1 and TryCatch0
1 parent 53700dc commit e128256

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

core/src/main/java/fj/Try.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package fj;
22

3+
import fj.data.IO;
4+
import fj.data.IOFunctions;
35
import fj.data.Validation;
46

7+
import java.io.IOException;
8+
59
/**
610
* Created by mperry on 24/07/2014.
711
*/
@@ -43,4 +47,8 @@ public static <A, B, C, D, E, Z extends Exception> F4<A, B, C, D, Validation<Z,
4347
return F8Functions.toF8(t);
4448
}
4549

50+
public static <A> IO<A> io(TryCatch0<A, ? extends IOException> t) {
51+
return IOFunctions.io(t);
52+
}
53+
4654
}

core/src/main/java/fj/data/IOFunctions.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,23 @@ public class IOFunctions {
3030

3131
private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
3232

33-
public static final F<Reader, IO<Unit>> closeReader =
33+
public static <A> TryCatch0<A, IOException> toTry(IO<A> io) {
34+
return () -> io.run();
35+
}
36+
37+
public static <A> P1<Validation<IOException, A>> p(IO<A> io) {
38+
return Try.f(toTry(io));
39+
}
40+
41+
public static <A> IO<A> io(P1<A> p) {
42+
return () -> p._1();
43+
}
44+
45+
public static <A> IO<A> io(TryCatch0<A, ? extends IOException> t) {
46+
return () -> t.f();
47+
}
48+
49+
public static final F<Reader, IO<Unit>> closeReader =
3450
new F<Reader, IO<Unit>>() {
3551
@Override
3652
public IO<Unit> f(final Reader r) {

0 commit comments

Comments
 (0)