Closed LiLatee closed 6 months ago
Why do you need a separate class for that? Adding a new subtype to a sealed class is a breaking change.
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);
}
Adding a new subtype to a sealed class is a breaking change.
Yes, I've noticed that 😅 So you are right, it's better to just add a factory. Seems to work fine in my case 👌 Idk why I complicated it so much 😞 Thanks!
final nit:
Thinking about it, I think .ofNullable
is not a great name for the behavior "present if not null, absent otherwise".
What about Value.absentWhenNull()
? of can you think of something more descriptive?
Regarding the name I was thinking about Value.valueOrAbsent
, but I have to admit that your absentWhenNull
looks better 👌 Changed
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.