Wanted more info on difference between javaslang Try.of() and Try.run()
For example
Try.of(() -> Integer.valueOf(str)).getOrElse(1) compiles fine but
Try.run(() -> Integer.valueOf(str)).getOrElse(1) does not.
found in the package javaslang.control .
More info on the library:
Try.of()takes aCheckedSupplier, which has aget()method to "get a result".Try.run()takes aCheckedRunnable, which has avoid run()method to "perform side-effects".Says so right there in the documentation.
The difference is the same as between a standard Java
Supplier("represents a supplier of results") andRunnable("execute code ... may take any action whatsoever"). One is for retrieving a value, the other is for executing some code.For examples of difference in use, see:
andThenTry(CheckedConsumer<? super T> consumer)andThenTry(CheckedRunnable runnable)