diff --git a/src/main/java/com/soumakis/control/IO.java b/src/main/java/com/soumakis/control/IO.java index 471cd62..f1731fc 100644 --- a/src/main/java/com/soumakis/control/IO.java +++ b/src/main/java/com/soumakis/control/IO.java @@ -193,6 +193,17 @@ public IO 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 fromTry(Try tryValue) { + return new IO<>(tryValue::get); + } + /** * Executes the encapsulated computation and returns the result. * Warning: This method performs the side effects and should be used cautiously,