Date: 2020-10-16
Author: Ben Weidig
Add JSR310 / Java Time CoercionTuple
s to Tapestry.
Type of Return | |
Operation Stream Operations Type | |
───────────────────────────────────────────────────────────────────────────────────────────────────── | |
┌──────────────────────────────────────────────────────────────┐ | |
Source │ Book Book Book Book Book Book Book Book Book │ List<Book> | |
└─────────────────────────────┬────────────────────────────────┘ | |
│ | |
v | |
┌──────────────────────────────────────────────────────────────┐ |
Either<Integer, String> result = doWork(); | |
result.apply(errorCode -> log.error("Error {} occuring during work", errorCode), | |
value -> log.info("Success: {}", value)); |
import java.util.Optional; | |
import java.util.function.Consumer; | |
import java.util.function.Function; | |
public class Either<L, R> { | |
public static <L, R> Either<L, R> left(L value) { | |
return new Either<>(value, null); | |
} |
interface FileLoader { | |
Optional<String> loadContent() throws IOException; | |
} |
interface FileLoader { | |
String loadContent() throws FileNotFoundException; | |
} |
try { | |
// might throw IOException | |
doWork(); | |
doMoreWorkRequireingCleanup(); | |
} | |
catch (IOException e) { | |
throw new RuntimeExcetpion(e) | |
} | |
finally { |
try { | |
// might throw IllegalArgumentException | |
doWork(); | |
// might throw ArithmeticException | |
doMoreWork(); | |
} | |
catch (IllegalArgumentExcetion e) { | |
// handle exception | |
} |
try { | |
doWork(); | |
} | |
catch (Exception e) { | |
// NO-OP | |
} |
try { | |
doWork(); | |
} | |
catch (NullPointerException e) { | |
log.error("doWork() failed", e); | |
throw e; | |
} |