dart_functional_data
dart_functional_data copied to clipboard
Possible to generate `merge` and `apply` methods too?
Hi! First off, I love this package. It has solved so many problems for me.
My current use case is when a user signs in, I have their configuration for the app saved in Firebase. If it's their first time signing in, I have to populate it with reasonable empty fields. This is what that currently looks like:
// Configuration extends $Configuration and also uses json_serializable
//
// Inside document.get().then((snapshot) =>
final empty = Configuration.empty();
if (snapshot.exists) {
final configuration = Configuration.fromJson(snapshot.data);
await configurationDocument.setData(
Configuration(
primaryColor: configuration.primaryColor ?? empty.primaryColor,
// A lot more fields . . .
).toJson(),
);
} else {
await configurationDocument.setData(empty.toJson());
}
With merge I think could just say something like:
await configurationDocument.setData(
configuration.merge(empty).toJson()
);
This seems like a useful feature.