Skip to content

Commit 14cb27f

Browse files
committed
CheckedRunnable is an IO
1 parent 1348fc7 commit 14cb27f

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
2020
- `Either#diverge` returns a `Choice3`
2121
- `Maybe` is now a `CoProduct2` of `Unit` and `A`
2222
- `Fn0` now additionally implements `Callable`
23+
- `CheckedRunnable` is an `IO<Unit>`
2324

2425
### Added
2526
- `Predicate#predicate` static factory method

src/main/java/com/jnape/palatable/lambda/functions/specialized/checked/CheckedRunnable.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.jnape.palatable.lambda.functions.specialized.checked;
22

33
import com.jnape.palatable.lambda.adt.Unit;
4+
import com.jnape.palatable.lambda.functions.IO;
45

56
import static com.jnape.palatable.lambda.adt.Unit.UNIT;
67
import static com.jnape.palatable.lambda.functions.specialized.checked.Runtime.throwChecked;
@@ -13,7 +14,14 @@
1314
* @see CheckedFn1
1415
*/
1516
@FunctionalInterface
16-
public interface CheckedRunnable<T extends Throwable> extends Runnable {
17+
public interface CheckedRunnable<T extends Throwable> extends Runnable, IO<Unit> {
18+
19+
/**
20+
* A version of {@link Runnable#run()} that can throw checked exceptions.
21+
*
22+
* @throws T any exception that can be thrown by this method
23+
*/
24+
void checkedRun() throws T;
1725

1826
@Override
1927
default void run() {
@@ -24,12 +32,11 @@ default void run() {
2432
}
2533
}
2634

27-
/**
28-
* A version of {@link Runnable#run()} that can throw checked exceptions.
29-
*
30-
* @throws T any exception that can be thrown by this method
31-
*/
32-
void checkedRun() throws T;
35+
@Override
36+
default Unit unsafePerformIO() {
37+
run();
38+
return UNIT;
39+
}
3340

3441
/**
3542
* Convert this {@link CheckedRunnable} to a {@link CheckedSupplier} that returns {@link Unit}.

0 commit comments

Comments
 (0)