The C++23 standard introduced a monadic interface for std::optional<T>.
- transform(f(T)->U)->std::optional<U>
only invoked when the source isn't empty
- and_then(f(T)->std::optional<U>)->std::optional<U>
only invoked when the source isn't empty
- or_else(f()->std::optional<T>)->std::optional<T>
only invoked when the source is empty
Compiler Explorer link: https://compiler-explorer.com/z/4dzc776Gq