patch 1.0.1
patch: ^1.0.1 copied to clipboard
A wrapper for copyWith arguments, so that a nullable field can be cleared as well as replaced.
1.0.1 #
- Rewrote the README's explanation of why
resolveis an extension, and normalized the file's formatting. - No library changes.
1.0.0 #
- Added
Patch<T>, a sealed wrapper forcopyWitharguments that tells an omitted argument apart from one supplied asnull. - Added the
Value<T>andUnchanged<T>variants, which respectively replace a field and leave it alone. - Added
Clear, aValue<Null>naming the intent to null out a field. It satisfiesPatch<T?>but noPatch<T>, so clearing a non-nullable field is a compile error, and aValue(...)pattern already matches it. - Added
resolve, an extension method onPatch<T>folding a patch against a field's current value, so acopyWithbody needs no switch. It is an extension rather than a method so that clearing a populated field does not trip Dart's covariance check onClear'sNulltype argument. - Added
==,hashCode, andtoStringto the variants. Equality is by wrapped value and ignores type arguments, soValue('a') == Value('a'), allUnchangeds are equal, andClear() == Value(null). Valueisfinal, so it cannot be subclassed outside this library. An external subclass would compare equal to a plainValuein one direction only, breaking the symmetry that map and set membership rely on.- Requires Dart 3.7 or later.