Result openFileStream(String filename) { try { return Result.ok(new FileInputStream(filename)); } catch (FileNotFoundException e) { return Result.err(e); } } ... InputStream defaultStream = System.in; InputStream workWithStream = openFileStream("no such file").project( stream -> stream, notFound -> defaultStream ); openFileStream("no such file").handle( stream -> workWithStream(inputStream), err -> System.out.println("Failed to open file " + err.getMessage()) ); openFileStream().toOptional() .map(stream -> extractInfoFromStream(stream)) .ifPresent(System.out::println); ... public interface AuthenticationService { ... ResultTriple signIn(String login, String password); } ... stubFor(postToLoginApi.willReturn(aResponse() .withFault(Fault.MALFORMED_RESPONSE_CHUNK))); assertTrue( authService.signIn("login", "password").project( token -> false, authenticationFailed -> false, serverConnectionFailed -> true) ); ... boolean isSuccessful = authService.signIn("login", "password").project( token -> { assertEquals(token.getTokenString(), "test_token"); assertTrue(authService.isSignedIn()); return true; }, authenticationFailed -> false, serverConnectionFailed -> false ); assertTrue(isSuccessful);