40. Checking a user name
User u = getUser(“Fred”);
Boolean result = null;
if (u != null)
Result = checkName(u.getName());
else
Result = false;
41. Checking a user name
Optional<User> u = getUser("Fred");
Boolean result;
if (u.isPresent())
result = confirmName(u.get().name);
else
result = false;
42. Confirming a user name with map()
Boolean result = getUser("Fred")
.map(u -> u.name)
.map(this::confirmName)
.orElse(false);
43. Optional is just a monad, a
monoid in the category of
endofunctors.
What’s the problem?
44. Optional is just a monad, a
monoid in the category of
endofunctors.
What’s the problem?
45. Optional is a zero- or one-
sized collection that helps
you cleanly handle
missing values.