Daily bit(e) of C++ | Monadic interface for std::optional
Daily bit(e) of C++ #190, The C++23 monadic interface for std::optional.
The C++23 standard introduced a monadic interface for std::optional<T>.
transform(f(T)->U)->std::optional<U>
If the source is not empty, it invokes a transformation function f(T)→U and wraps the result in std::optional<U>.and_then(f(T)->std::optional<U>)->std::optional<U>
If the source is not empty, it invokes a transformation function f(T)→std::optional<U> and returns the result.or_else(f()->std::optional<T>)->std::optional<T>
If the source is empty, it invokes the generation function f()→std::optional<T> and returns the result.
love it