Skip to content

Instantly share code, notes, and snippets.

@Opalo
Created October 12, 2018 06:08
Show Gist options
  • Save Opalo/6372e432d1173ed86c3e3dcd1529cce5 to your computer and use it in GitHub Desktop.
Save Opalo/6372e432d1173ed86c3e3dcd1529cce5 to your computer and use it in GitHub Desktop.
import io.vavr.collection.List;
import io.vavr.control.Try;
class Lol {
public static void main(String[] args) {
final List<Node> myNodeList = Try.of(NodeUtils::new)
.onFailure(System.out::println)
.mapTry(NodeUtils::retrieveNodes)
.getOrElse(List.empty());
System.out.println(myNodeList.isEmpty());
}
}
class Node {
}
class NodeUtils {
String myStr = methodThatThrowsAnException();
public List<Node> retrieveNodes() {
return List.of(new Node());
}
private String methodThatThrowsAnException() {
if (true) {
throw new RuntimeException("bang!");
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment