Scala 中的 IEnumerable LINQ 等价物图表?
可能的重复:
Scala 中的 LINQ 类似物
我正在寻找显示 IEnumerable 的 LINQ 方法在 Scala 中的等效项的图表:
- 首先是 head
- Select 是 map
- SingleOrDefault 是...(我不知道)
- ...等等
有谁知道这样的“翻译”表吗?
Possible Duplicate:
LINQ analogues in Scala
I am looking for chart which shows equivalents in Scala of LINQ methods for IEnumerable:
- First is head
- Select is map
- SingleOrDefault is ... (I don't know)
- ... and so on
Does anyone know anything of such "translate" table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只是列出了
Enumerable
中的函数的等效项。截至目前,这还不完整。我稍后会尝试更新更多内容。某些功能没有直接等效的功能,但开发自己的功能相当容易。这里有一些这样的函数。
单个:
SingleOrDefault:
加入:
GroupJoin:
注释:
惯用语Scala,总体函数通常优于部分函数。因此,
single
和singleOrDefault
的惯用实现将生成Either[Exception, A]
类型的值,而不是A
>。例如,这里是single
的精炼实现,它返回Either[Exception, A]
。Scalaz 的
Zero
/mzero
与 C# 的default
值机制不太一样。具体可以参考这个 我之前就这个主题写过一篇文章。您可以使用丰富我的库模式来达到与 C# 扩展方法相同的效果。请参阅此和此了解详细信息。
I am only listing out the equivalents of functions from
Enumerable<A>
. This is incomplete as of now. I will try to update this later with more.There is no direct equivalent of some functions, but it's fairly easy to roll your own. Here are some such functions.
Single:
SingleOrDefault:
Join:
GroupJoin:
Notes:
In idiomatic Scala, total functions are generally preferred over partial functions. So, idiomatic implementation of
single
andsingleOrDefault
would produce a value of typeEither[Exception, A]
instead ofA
. For example, here is refined implementation ofsingle
that returnsEither[Exception, A]
.Scalaz's
Zero
/mzero
are not quite same as C#'sdefault
value mechanism. For details, you can refer to this post I wrote on this topic some time back.You can use enrich-my-library pattern to achieve the same effect as C#'s extension methods. Refer to this and this for details.
我对 C# 或 LINQ 一无所知,但这就是您要找的吗?
没有方法可以获取元素或默认值,但这可以工作:
I don't know anything about C# or LINQ, but is this what you're looking for?
There's no method to get an element or a default, but this will work: