File tree Expand file tree Collapse file tree 4 files changed +30
-47
lines changed
core/src/main/java/fj/data
demo/src/main/java/fj/demo Expand file tree Collapse file tree 4 files changed +30
-47
lines changed Original file line number Diff line number Diff line change 44 * Created by MarkPerry on 19/06/2014.
55 */
66
7+ import fj .F ;
8+ import fj .Unit ;
9+
710import java .io .IOException ;
811
912/**
1316 *
1417 * @param <A> the type of the result produced by the IO
1518 */
19+ @ FunctionalInterface
1620public interface IO <A > {
1721
1822 A run () throws IOException ;
1923
24+ default SafeIO <Validation <IOException , A >> safe () {
25+ return IOFunctions .toSafeValidation (this );
26+ }
27+
28+ default <B > IO <B > map (F <A , B > f ) {
29+ return IOFunctions .map (this , f );
30+ }
31+
32+ default <B > IO <B > bind (F <A , IO <B >> f ) {
33+ return IOFunctions .bind (this , f );
34+ }
35+
36+ default <B > IO <B > append (IO <B > iob ) {
37+ return IOFunctions .append (this , iob );
38+ }
39+
40+ public static IO <LazyString > getContents () {
41+ return () -> IOFunctions .getContents ().run ();
42+ }
43+
44+ public static IO <Unit > interact (F <LazyString , LazyString > f ) {
45+ return () -> IOFunctions .interact (f ).run ();
46+ }
47+
2048}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 33/**
44 * Created by MarkPerry on 3/07/2014.
55 */
6+ @ FunctionalInterface
67public interface SafeIO <A > extends IO <A > {
78
89 @ Override
Original file line number Diff line number Diff line change 44import fj .Unit ;
55import fj .data .IO ;
66import fj .data .IOFunctions ;
7- import fj .data .IOW ;
87
98import java .io .BufferedReader ;
109import java .io .IOException ;
@@ -72,7 +71,7 @@ public static void main(String[] args) {
7271 // for composing IO values instead, the entire program can be written like so:
7372
7473 F <String , String > f = String ::toUpperCase ;
75- IOW . lift ( stdoutPrintln ("What's your name again?" ) )
74+ stdoutPrintln ("What's your name again?" )
7675 .append (stdoutPrint ("Name: " ))
7776 .append (stdinReadLine ())
7877 .bind (f .andThen (IOFunctions ::stdoutPrintln ))
You can’t perform that action at this time.
0 commit comments