Daily bit(e) of C++ | std::expected, monadic interface
Daily bit(e) of C++ #364, Monadic interface of the C++23 std::expected.
The std::expected (C++23) comes with a monadic interface. Relying on the monadic interface prevents the typical if-then-else verbose error checking.
The and_then and or_else methods expect a callable that accepts a value/error and returns a std::expected.
The transform and transform_error methods expect a callable that accepts a value/error and returns a value/error.