-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#feat: Add value or absent option #449
#feat: Add value or absent option #449
Conversation
Why do you need a separate class for that? And there are no new states - a value is either present or absent. we don't need a separate type for this, this could be a static method or factory, couldn't it? factory Value.ofNullabe(T? t) {
if(t == null} {
return Value.absent();
}
return Value.present(t);
} |
Yes, I've noticed that 😅 |
group( | ||
'requireValue', | ||
() { | ||
test('on $AbsentValue throws', () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sure ${Value.ofNullable}
should not be there. I forgot to check how it looks like in logs.
But personally I like to use e.g. $AbsentValue
, because it's very helpful when refactoring the code. You don't have to remember about every place in the code where you have just a string with the class name.
But I changed all the names to static ones 👌
/// If the value is null. It will not be serialized. | ||
factory Value.ofNullable(T? value) { | ||
if (value == null) { | ||
return AbsentValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be const?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be... My mistake. I am used to having a lint prefer_const_constructors
😅 Thanks 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I know, gql_pedantic should be modernized at some point ;)
final nit: Thinking about it, I think What about |
Regarding the name I was thinking about |
thanks! lgtm |
Hey! 👋
I've been lacking the option to send a value if it exists and not send any value (neither null) if not present.
EDIT: Converted to DRAFT, because it's not working yet.