patch 1.0.1 copy "patch: ^1.0.1" to clipboard
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 resolve is an extension, and normalized the file's formatting.
  • No library changes.

1.0.0 #

  • Added Patch<T>, a sealed wrapper for copyWith arguments that tells an omitted argument apart from one supplied as null.
  • Added the Value<T> and Unchanged<T> variants, which respectively replace a field and leave it alone.
  • Added Clear, a Value<Null> naming the intent to null out a field. It satisfies Patch<T?> but no Patch<T>, so clearing a non-nullable field is a compile error, and a Value(...) pattern already matches it.
  • Added resolve, an extension method on Patch<T> folding a patch against a field's current value, so a copyWith body needs no switch. It is an extension rather than a method so that clearing a populated field does not trip Dart's covariance check on Clear's Null type argument.
  • Added ==, hashCode, and toString to the variants. Equality is by wrapped value and ignores type arguments, so Value('a') == Value('a'), all Unchangeds are equal, and Clear() == Value(null).
  • Value is final, so it cannot be subclassed outside this library. An external subclass would compare equal to a plain Value in one direction only, breaking the symmetry that map and set membership rely on.
  • Requires Dart 3.7 or later.
0
likes
160
points
146
downloads

Documentation

API reference

Publisher

verified publisherandyhorn.dev

Weekly Downloads

A wrapper for copyWith arguments, so that a nullable field can be cleared as well as replaced.

Repository (GitHub)
View/report issues

Topics

#copywith #immutability #data-classes

License

MIT (license)

Dependencies

meta

More

Packages that depend on patch