Search code examples
c++c++23std-expected

Why are there no monadic operations in std::expected?


In C++23, monadic operations in std::optional was adopted, and later on std::expected. Why were monadic operations like and_then, transform, and or_else not included in the main paper?


Solution

  • Update: std::expected in C++23 will have monadic operations.


    The std::expected proposal is very old. The adopted revision is P0323R12, which already suggests a long life, but that paper even predates the P-numbering system and started out as N4015, dated May 2014.

    I bring this up because std::expected, even by itself, has taken a very long time to wind its way through the process. In contrast, the monadic operations for std::optional paper only first appeared in October 2017. And since then it was just a long slog just to get std::expected at all.

    There is a paper proposing monadic operations for std::expected, that's P2505R0, but at this point it's very incomplete and needs a lot of work. The design window for new C++23 features is closed, but I wouldn't be surprised if there were an NB comment requesting it in later anyway.

    At least we finally have std::expected.


    Coming in here a few months later, there was an NB comment requesting the monadic operators for std::expected and P2505R5 was adopted for C++23 in Kona in November 2022.