Add compose_first_error_and_result, closes #265#329
Merged
Conversation
Pairs a possibly-failing side-effecting function (e.g. logging) with a regular result-returning function. Both are called on the same input; the second runs regardless of whether the first one failed. The error of the first is preserved as a Maybe alongside the second's Result. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The combinator is not specific to logging — it fits any ancillary check that may fail but should not block the main computation (validation, metrics, audit, cache lookup, ...). Generalize the name and the doc comment accordingly. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
std::monostate requires C++17 but the project compiles as C++14, so the test broke every CI compiler. The Ok value of the first function is discarded by the combinator anyway, so any type works -- use int. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
compose_first_error_and_resultinresult.hpp: runs twoResult-returning functions on the same input independently.Maybe); its Ok value is discarded.Resultis forwarded unchanged, and the second is always called regardless of whether the first failed.Resolves the design discussed in #265.
Test plan
result_test - compose_first_error_and_resulttest case covers all four combinations: (first ok / fail) × (second ok / fail).ctest: 424/424).generate/auto_generate.pyran; amalgamatedinclude_all_in_one/include/fplus/fplus.hppupdated.🤖 Generated with Claude Code