Lifting adapts an ordinary function so it operates on values inside a computational context such as Optional. Instead of manually unpacking, checking, and rebuilding Optional values, lift moves the function into that context while preserving its original logic. section 7.12 section 7.8.2
A binary lifter follows a small sequence of generalizations:
- Start with an operation that handles two present Optional values and returns Optional.empty() when either value is absent. section 7.8.2
- Pass the BinaryOperator into that pattern, then generalize the value type. section 7.8.2
- Separate the operator from its arguments so lift returns a BinaryOperator<Optional<A>>. section 7.8.2
Lifting familiar operations
lift(Integer::sum) produces a BinaryOperator<Optional<Integer>>, while lift(String::concat) produces a BinaryOperator<Optional<String>>. Applying the first to Optional.of(1) and Optional.of(2) yields Optional.of(3); applying the second with an empty operand yields Optional.empty().


