Add WithConstant factory methods for single constant Setter creation #56
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.
🤖 AI-Powered Solution
This pull request solves issue #7 by implementing static factory methods that allow creating
Setter<TResult, TDecision>instances with a single constant value.📋 Issue Reference
Fixes #7 - Think about setter with single constant, without True/False cases
🔧 Implementation Details
Problem
The issue identified that "in real life usage only one constant is actually used," but the current API required specifying both true and false values:
Solution
Added two static factory methods to
Setter<TResult, TDecision>class:WithConstant(TDecision constantValue)- Creates a setter with the same constant for both true/false casesWithConstant(TDecision constantValue, TResult defaultValue)- Same as above but with a specified default result valueUsage Examples
✅ Changes Made
WithConstant(constantValue)andWithConstant(constantValue, defaultValue)WithConstantFactoryMethodTestandWithConstantAndDefaultValueFactoryMethodTestexperiments/SingleConstantSetterDemo.csshowing real-world usageTResultandTDecisionare the same type🧪 Testing
All tests pass (6/6):
📚 Design Rationale
Why static factory methods instead of constructors?
TResultandTDecisionare the same type (e.g.,Setter<uint, uint>)The implementation addresses the core need expressed in the issue while maintaining clean, unambiguous API design.
🤖 Generated with Claude Code