scala 2.8 集合不一致?
为什么方法transform
(map
的就地突变版本)和retain
(filter
的就地突变版本>) 仅在 mutable.Map
上定义,但不在 mutable.Buffer
和 mutable.Set
上定义?所有可变集合不都应该支持这些方法吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Map
是关于键和值的概念,这些概念不属于设置
或缓冲区
。但您的操作列在:
一零零一评论:
我认为
retain
和transform
为诸如地图
和
过滤器
来自TraversableLike
。在
Set
和Buffer
中实现transform
不会增加任何价值,因为它只是与map
不同。注意:Michael Kebe 评论:
(与
mutable.MapLike
两者都有)
但这似乎符合 转换操作 如果转换通过过滤和转换现有地图的绑定生成新地图。
这是 转换源代码
retain
的源代码,却修改了当前实例,只能兼容Mutable对象:The operations
retain
andtransform
ofMap
are about keys and values, concepts which are not part of aSet
or aBuffer
.But your operations are listed in:
one-zero-zero-one comments:
I would argue that
retain
andtransform
offer Map-specific implementations (in that their implementation specifically deals with keys and values) for features like the ones provided bymap
andfilter
fromTraversableLike
.Implementing
transform
inSet
andBuffer
would add little value as it would simply deffer tomap
.Note: Michael Kebe comments:
(as opposed to
mutable.MapLike
which has both)This seems however in-line with the nature of transformation operations if transform produces a new map by filtering and transforming bindings of an existing map.
Here is the source code for transform
Source code for
retain
, however, modified the current instance, which can only be compatible with Mutable objects: