-
Notifications
You must be signed in to change notification settings - Fork 87
IterableView#filterKeys and #mapValues cannot be chained #294
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
Comments
Edit: just ignore the comment, I misread the signature…
|
Do you have an idea what the Would it be possible to fix both operations by providing |
According to IntelliJ, the For reference, the type of
I'm not super great at finding the right |
By adding the following // CanBuildFrom instances for `IterableView[(K, V), Map[K, V]]` that preserve
// the strict type of the view to be `Map` instead of `Iterable`
implicit def canBuildFromIterableViewMapLike[K, V, L, W, CC[X, Y] <: c.Map[X, Y]]: CanBuildFrom[c.IterableView[(K, V), CC[K, V]], (L, W), c.IterableView[(L, W), CC[L, W]]] =
new CanBuildFrom[c.IterableView[(K, V), CC[K, V]], (L, W), c.IterableView[(L, W), CC[L, W]]] {
// `CanBuildFrom` parameters are used as type constraints, they are not used
// at run-time, hence the dummy builder implementations
def apply(from: c.IterableView[(K, V), CC[K, V]]) = new c.TraversableView.NoBuilder
def apply() = new c.TraversableView.NoBuilder
} I’m not saying that this is a simpler approach, though… What do you think? |
@julienrf sorry I haven't gotten around to replying until now. I think this approach is a good stopgap to allow compatibility until we can change the underlying implementation of IMO, we should change |
Yes, let’s do that! |
I'll update #295 |
With the current extension methods, (as of 2badce8), you cannot chain
filterKeys
andmapValues
on anIterableView[_, _ <: Map]
. I believe the reason for this is that both take aCanBuildFrom
and return aThat
, unlike their corresponding 2.12 methods. ThefilterKeys
extension is even particularly egregious, asfilter
methods always return the same type and do not ever take aCanBuildFrom
.The methods are currently defined as:
The following definitions do not use
CanBuildFrom
and can chain with each other:Unfortunately,
mapValues
has already been in previous releases, so its signature cannot be changed without a new release. However, we can still change the implementation offilterKeys
(at least as of the aforementioned commit), as it has not been in any release yet. This allows the (I believe more common) use of.view.filterKeys(...).mapValues(...)
, though not.view.mapValues(...).filterKeys(...)
.The text was updated successfully, but these errors were encountered: