Feature Request
Inspired by RecordBuilder's per-field wither pattern, where each field gets a withXxx(value) method that returns a new instance with only that field changed.
Current State
Simple-builder already has a With interface with a consumer-based with(Consumer<Builder>) method that is more flexible but more verbose for single-field changes:
// Current: consumer-based (more flexible)varmodified = original.with(b => b.accreditationName("new value"));
// Proposed: per-field wither (more concise)varmodified = original.withAccreditationName("new value");Proposed Configuration
Add a tri-state configuration to @SimpleBuilder:
| Value | Behavior |
|---|
ENABLE | Generate per-field withers for all supported types (records and classes) |
RECORDS_ONLY | Generate per-field withers only for record types (where implementation is trivial via canonical constructor) |
DISABLE (default) | Do not generate per-field withers |
Why tri-state?
RECORDS_ONLY: Records have a canonical constructor making per-field withers trivial and efficient (new Record(field1, newValue, field3, ...))ENABLE: For classes, implementation requires a copy constructor or re-reading all fields — more complex and potentially slowerDISABLE: Keeps default behavior unchanged; existing consumer-based With interface already covers this use case
Implementation Notes
- For records:
withXxx(value) => new Record(accessor1(), value, accessor3(), ...) - For classes:
withXxx(value) => create builder from instance via copy constructor, set field, build - Should be generated in the
With interface alongside existing with(Consumer) and with() methods - Consider method naming convention:
withXxx() vs withXxxValue()
Priority
Lower priority than field getters. The existing consumer-based With interface already covers this use case albeit more verbosely.
Feature Request
Inspired by RecordBuilder's per-field wither pattern, where each field gets a
withXxx(value)method that returns a new instance with only that field changed.Current State
Simple-builder already has a
Withinterface with a consumer-basedwith(Consumer<Builder>)method that is more flexible but more verbose for single-field changes:Proposed Configuration
Add a tri-state configuration to
@SimpleBuilder:ENABLERECORDS_ONLYDISABLE(default)Why tri-state?
RECORDS_ONLY: Records have a canonical constructor making per-field withers trivial and efficient (new Record(field1, newValue, field3, ...))ENABLE: For classes, implementation requires a copy constructor or re-reading all fields — more complex and potentially slowerDISABLE: Keeps default behavior unchanged; existing consumer-basedWithinterface already covers this use caseImplementation Notes
withXxx(value)=>new Record(accessor1(), value, accessor3(), ...)withXxx(value)=> create builder from instance via copy constructor, set field, buildWithinterface alongside existingwith(Consumer)andwith()methodswithXxx()vswithXxxValue()Priority
Lower priority than field getters. The existing consumer-based
Withinterface already covers this use case albeit more verbosely.