Skip to content

Commit 8e88796

Browse files
committed
IO internal rewrite
- now sealed - linear and recursive composition is stack-safe - static factory methods are now much easier to infer
1 parent 911e549 commit 8e88796

8 files changed

Lines changed: 225 additions & 131 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/).
55

66
## [Unreleased]
7-
No changes
7+
### Changed
8+
- ***Breaking Change***: `IO` is now sealed. Most previous constructions using the static factory methods
9+
should continue to work (by simply targeting `Supplier` now instead of an anonymous `IO`), but some might
10+
need to be reworked, and subtyping is obviously no longer supported.
11+
- `IO` is now stack-safe, regardless of whether the composition nests linearly or recursively
812

913
## [3.3.0] - 2019-02-18
1014
### Added

src/main/java/com/jnape/palatable/lambda/functions/Effect.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.util.function.Consumer;
77
import java.util.function.Function;
88

9-
import static com.jnape.palatable.lambda.functions.Fn0.fn0;
109
import static com.jnape.palatable.lambda.functions.IO.io;
1110
import static com.jnape.palatable.lambda.functions.builtin.fn1.Constantly.constantly;
1211

@@ -22,7 +21,7 @@ public interface Effect<A> extends Fn1<A, IO<Unit>>, Consumer<A> {
2221

2322
@Override
2423
default IO<Unit> apply(A a) {
25-
return io(fn0(() -> accept(a)));
24+
return io(() -> accept(a));
2625
}
2726

2827
@Override

src/main/java/com/jnape/palatable/lambda/functions/Fn0.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.function.Supplier;
1010

1111
import static com.jnape.palatable.lambda.adt.Unit.UNIT;
12-
import static com.jnape.palatable.lambda.functions.IO.io;
1312

1413
/**
1514
* A function taking "no arguments", implemented as an <code>{@link Fn1}&lt;{@link Unit}, A&gt;</code>.
@@ -124,7 +123,10 @@ static <A> Fn0<A> fn0(Fn0<A> fn) {
124123
* @return the {@link Fn0}
125124
*/
126125
static Fn0<Unit> fn0(Runnable runnable) {
127-
return io(runnable)::unsafePerformIO;
126+
return fn0(() -> {
127+
runnable.run();
128+
return UNIT;
129+
});
128130
}
129131

130132
/**

0 commit comments

Comments
 (0)