Skip to content

Add apply and apply_type to optional and expected #339

Description

@Bronek

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestrelease-0.1Planned for release 0.1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions