June 2018
Intermediate to advanced
280 pages
7h 46m
English
Applicatives add a new level of wrapping—instead of applying a function to a wrapped object, the function is wrapped too. In the following code, the function is wrapped in an optional. To prove one of the applicatives' usages, we also provide an identity (everything remains the same) optional in case the desired function (toUpperCase in our case) is empty. Since there is no syntax sugar to automatically apply a wrapped function, we need to do that manually—see the get().apply() code. Notice the usage of the Java 9 added method Optional.or(), which returns another Optional lazily, in case our input Optional is empty:
jshell> Optional<String> a = Optional.of("Hello Applicatives")a ==> Optional[Hello Applicatives]jshell> Optional<Function<String, ...Read now
Unlock full access