Skip to content

Commit b0318d3

Browse files
committed
Implemented real world haskell IO (chapter 7) demonstration, implementing
interact for IO. Various changes to support lazy IO and infinite streams. Made P1 toString lazy, this was causing problems in the debugger using infinite structures. Made LazyString.toString lazy, returning the first character. Added map, bind and eval methods to LazyString. Added IO wrapper, implementing static methods from IOFunctions as instance methods. Made Stream.take evaluate one less element, made toString lazy. Added Strings methods lines and unlines. Implemented IOFunctions interact and getContents. Made sequenceWhile lazy, suitable for IO. Test that toString for an infinite stream is lazy. Demonstrate lazy use of sequenceWhile. Refactor from changes to IOFunctions. Test converting an infinite stream of lazy strings to a string. Ensure no stack overflow occurs as in version 4.3. Added demonstrations of IOFunctions.interact
1 parent 1ba2f25 commit b0318d3

File tree

12 files changed

+707
-377
lines changed

12 files changed

+707
-377
lines changed

core/src/main/java/fj/Show.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,14 @@ public static <A> Show<Class<A>> classShow() {
422422
* @return A show instance for the {@link P1 tuple-1} type.
423423
*/
424424
public static <A> Show<P1<A>> p1Show(final Show<A> sa) {
425+
return p1ShowLazy(sa);
426+
}
427+
428+
public static <A> Show<P1<A>> p1ShowLazy(final Show<A> sa) {
429+
return show(p -> Stream.fromString("(?)"));
430+
}
431+
432+
public static <A> Show<P1<A>> p1ShowEager(final Show<A> sa) {
425433
return show(p -> cons('(', p(sa.show(p._1()))).snoc(')'));
426434
}
427435

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public static <A, B, C, D, E, F, G, H, I, Z extends Exception> F8<A, B, C, D, E,
160160
}
161161

162162
public static <A> IO<A> io(Try0<A, ? extends IOException> t) {
163-
return IOFunctions.io(t);
163+
return IOFunctions.fromTry(t);
164164
}
165165

166166
}

0 commit comments

Comments
 (0)