Skip to content

Commit

Permalink
Utility method in IO
Browse files Browse the repository at this point in the history
  • Loading branch information
VassilisSoum committed Aug 18, 2024
1 parent 4a92684 commit 3d80235
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/com/soumakis/control/IO.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ public IO<A> repeat(int times) {
});
}

/**
* Creates an {@code IO} instance from a {@code Try} value. If the {@code Try} is a success, the
* computation will return the value; if it is a failure, the computation will throw the
* exception.
* @param tryValue The {@code Try} value to convert to an {@code IO}.
* @return An {@code IO} instance that encapsulates the {@code Try} value.
*/
public IO<A> fromTry(Try<A> tryValue) {
return new IO<>(tryValue::get);
}

/**
* Executes the encapsulated computation and returns the result.
* <b>Warning:</b> This method performs the side effects and should be used cautiously,
Expand Down

0 comments on commit 3d80235

Please sign in to comment.