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 4
4
* Created by MarkPerry on 19/06/2014.
5
5
*/
6
6
7
+ import fj .F ;
8
+ import fj .Unit ;
9
+
7
10
import java .io .IOException ;
8
11
9
12
/**
13
16
*
14
17
* @param <A> the type of the result produced by the IO
15
18
*/
19
+ @ FunctionalInterface
16
20
public interface IO <A > {
17
21
18
22
A run () throws IOException ;
19
23
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
+
20
48
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 3
3
/**
4
4
* Created by MarkPerry on 3/07/2014.
5
5
*/
6
+ @ FunctionalInterface
6
7
public interface SafeIO <A > extends IO <A > {
7
8
8
9
@ Override
Original file line number Diff line number Diff line change 4
4
import fj .Unit ;
5
5
import fj .data .IO ;
6
6
import fj .data .IOFunctions ;
7
- import fj .data .IOW ;
8
7
9
8
import java .io .BufferedReader ;
10
9
import java .io .IOException ;
@@ -72,7 +71,7 @@ public static void main(String[] args) {
72
71
// for composing IO values instead, the entire program can be written like so:
73
72
74
73
F <String , String > f = String ::toUpperCase ;
75
- IOW . lift ( stdoutPrintln ("What's your name again?" ) )
74
+ stdoutPrintln ("What's your name again?" )
76
75
.append (stdoutPrint ("Name: " ))
77
76
.append (stdinReadLine ())
78
77
.bind (f .andThen (IOFunctions ::stdoutPrintln ))
You can’t perform that action at this time.
0 commit comments