What is the reason for `Map<K, V>.filterValu...
# stdlib
g
What is the reason for
Map<K, V>.filterValues
working directly on the values (i.e. it expects
(V) -> T
) as opposed to
Map<K, V>.mapValues
working on the entire entry (i.e. it expects
(Map.Entry<K, V>) -> T
)? Same question applies to the signature of
filterKeys
vs.
mapKeys
and similar functions.
v
Isn't it what
Map.filter
is working on?
s
An observation is it is the only difference with filterValues and filterKeys, filter is the parameter. I assume the reason you have different methods with
map
is to avoid returning pairs where the one component is always the same.
So for filter it is about specializing on the input paramter wheres with map it is specializing on the return value kind
d
The reason is simply convenience. There is Map.filter for filtering the entries as @voddan pointed out.