Follow-up to #268; intended for release-0.1, so the lower-level primitive reaches users right away — useful on its own, ahead of the verb-layer follow-up (#341).
sum and choice carry the pair (#84, #268). The other monads' states are also a closed alternative set — present/empty, value/error — and each state already has a constructor tag naming it. apply_type's tag types are selected to match the constructor tag of the monad in question:
optional<T> — std::in_place_t for the held value, std::nullopt_t for empty;
expected<T, E> — std::in_place_t for the value, fn::unexpect_t for the error.
Arms receive the tag followed by the state's content unpacked exactly as apply unpacks it (a pack or tuple-like payload by elements, a plain value whole; the nullopt_t arm receives the tag alone), and exhaustiveness over both states is required outright, as on sum. Note the tags differ by type between the rows, so apply_type on expected<T, E> is airtight by construction even where T and E interconvert — the same argument that motivated #268, landing on the tags the user already knows from construction. The untagged apply accompanies it as the shape-oriented counterpart. Both are the lower-level tool beside the monadic members, per the #268 scope refinement — the monadic verbs are untouched by this item; their type-indexed form is #341 (release-0.2).
Builds directly on the #268 machinery: the _apply_type_fn adapter and the tagged trait families are the intended foundation.
Follow-up to #268; intended for release-0.1, so the lower-level primitive reaches users right away — useful on its own, ahead of the verb-layer follow-up (#341).
sumandchoicecarry the pair (#84, #268). The other monads' states are also a closed alternative set — present/empty, value/error — and each state already has a constructor tag naming it.apply_type's tag types are selected to match the constructor tag of the monad in question:optional<T>—std::in_place_tfor the held value,std::nullopt_tfor empty;expected<T, E>—std::in_place_tfor the value,fn::unexpect_tfor the error.Arms receive the tag followed by the state's content unpacked exactly as
applyunpacks it (apackor tuple-like payload by elements, a plain value whole; thenullopt_tarm receives the tag alone), and exhaustiveness over both states is required outright, as onsum. Note the tags differ by type between the rows, soapply_typeonexpected<T, E>is airtight by construction even whereTandEinterconvert — the same argument that motivated #268, landing on the tags the user already knows from construction. The untaggedapplyaccompanies it as the shape-oriented counterpart. Both are the lower-level tool beside the monadic members, per the #268 scope refinement — the monadic verbs are untouched by this item; their type-indexed form is #341 (release-0.2).Builds directly on the #268 machinery: the
_apply_type_fnadapter and the tagged trait families are the intended foundation.