加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

惯用语Scala:Like和Types之间的语义差异?

发布时间:2020-12-16 08:51:40 所属栏目:安全 来源:网络整理
导读:正如这个问题的标题所暗示的那样:我的问题更多的是形式(惯用惯例)而不是功能.简洁地说: What is the semantic difference between MyCollectionLike and MyCollection ? 例如:StringLike和String或MapLike和Map之间有什么区别.仔细观察Scala API文档,我可
正如这个问题的标题所暗示的那样:我的问题更多的是形式(惯用惯例)而不是功能.简洁地说:

What is the semantic difference between MyCollectionLike and MyCollection?

例如:StringLike和String或MapLike和Map之间有什么区别.仔细观察Scala API文档,我可以看出XLike通常是X的超类型.但除此之外,我不清楚这些抽象层之间的语义差异.

在实践中,如果我正在创建一个新的类/特征,当我为所述类选择名称时,理解这种区别会很有帮助.

我提出的具体问题如下:

I want to create the trait: SurjectiveMap[K,T] which can be mixed-in with either Map[K,Set[T]] or MapLike[K,SetLike[T]]. Given that I do not know the semantic difference between *Like and *,I am not sure which to go with.

解决方法

与IFoo和Foo,Bar和BarImpl之间的区别相同(除了TraversableLike是包含实现的超级特征的事实):

The Scala collection library avoids code duplication and achieves the
“same-result-type” principle by using generic builders and traversals
over collections in so-called implementation traits. These traits are
named with a Like suffix; for instance,IndexedSeqLike is the
implementation trait for IndexedSeq,and similarly,TraversableLike is
the implementation trait for Traversable. Collection classes such as
Traversable or IndexedSeq inherit all their concrete method
implementations from these traits.

Scala collections architecture

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读