lettuce
lettuce copied to clipboard
ScoreValue.from return type
Hello! I am having problems to create a ScoredValue
from an Optional
value in the recent release 6.1.0.RELEASE
,
in which the signature ScoreValue.from(Double score, Optional<T> value)
now returns Value
instead of ScoredValue
, and I have to explicitly cast it to ScoreValue
in order to use it in the SortedStreams
api...
As I see the method is creating a ScoredValue so I think it would be better to return that type directly instead of using the parent Value
. What are your thoughts? Changing the type will be a breaking change so perhaps we could have a new method to address that?
Thanks for raising an issue. The problem is somewhat that a scored value that is empty isn't really useful because it represents a score only without a value. We tried to express the value optionality with changing the return type. There's a similar issue with the geo variant of Value
.
The way out is to map the optimal value with Optional.map(v -> ScoredValue.just(score, v).orElse(...)
.
Can you help us understand the context in which you're using ScoredValue
and how your code behaves if the Optional
is empty?
The problem is somewhat that a scored value that is empty isn't really useful because it represents a score only without a value.
Neither I find the application for empty ScoredValue
, and I was wondering if it can ever be the case where it is comes empty from one of the library methods. Because if there are no such cases maybe it would be easier to not allow Optional values (empty) to be passed and to work directly with the value with a NotNull
validation. But I am not sure...
In my case I have found that case while building a Scala and Monix friendly Redis client that actually is a wrapper around lettuce, but don't have specific scenario where that happens. This is the line where I found that problem.
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 30 days this issue will be closed.