You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think map should be applied only if payload is present.
It gives us the ability to chain map method whether the paylaod is present or not.
If you look at the java implementation, it is implemented that way.
public <U> Optional<U> map(Function<? superT, ? extendsU> mapper) {
Objects.requireNonNull(mapper);
if (!isPresent()) {
returnempty();
} else {
returnOptional.ofNullable(mapper.apply(value));
}
}
The current implementation force the developer to null-check value in the mapper. It seems kind of counter intuitive to me.
// currently I do thisthis.phone=Optional.ofNullable(builder.phone).map((phone)=>{if(phone){Assert.isValidPhoneNumber(builder.phone);returnnewName(phone);}returnundefined;});// while it could simply be this.phone=Optional.ofNullable(builder.phone).map((phone)=>{Assert.isValidPhoneNumber(builder.phone);returnnewName(phone);}});
I could suggest a PR if you're willing to accept this change.
The text was updated successfully, but these errors were encountered:
I think map should be applied only if payload is present.
It gives us the ability to chain map method whether the paylaod is present or not.
If you look at the java implementation, it is implemented that way.
The current implementation force the developer to null-check value in the mapper. It seems kind of counter intuitive to me.
I could suggest a PR if you're willing to accept this change.
The text was updated successfully, but these errors were encountered: