scala和java中的枚举器vs迭代器 [英] Enumerator vs Iterator in scala and java

查看:140
本文介绍了scala和java中的枚举器vs迭代器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Enumerator和Iterator有什么区别?根据我的理解枚举器不是Java中枚举的精美别名。相反,它似乎是一种类似于 Iterator 的遍历技术。那么有人能够比较和对比枚举器 Iterator ?此外,我在播放中看到一个用法为

What is the difference between Enumerator and Iterator? Per my understanding Enumerator is not a fancy alias for enum in Java. Rather, it seems to be a traversal technique similar to an Iterator. So is anyone able to compare and contrast Enumerator and Iterator? Also, I see a usage in Play as

val data = getDataStream
val dataContent: Enumerator[Array[Byte]] = Enumerator.fromStream(data)

编辑:

我倾向于认为 Enumerator 为我们提供了实际的数据块,而 Iterator 为我们提供了已经分块的数据的指针,例如列表。但我不相信情况就是这样。

I am inclined to think that Enumerator gives us actual chunks of data, whereas Iterator gives us pointers to data that is already chunked, such as a list. But I am not convinced that that's the case.

推荐答案

枚举器 Play类,而非Java或Scala版。

Enumerator is a Play class, not a Java or Scala one.

它是 Iteratee I / O的一部分处理提供的处理。 Iteratees是一个有趣的野兽 - 一方面,它将数据推送到处理程序,而不是依靠处理程序来提取数据,因此具有更好的性能。在其他手上,它允许处理程序控制何时应该停止流。最后,可以组成迭代,以便不同的迭代负责输入的不同部分(比如,一个接收HTTP头,另一个接收它的主体)以及链接它们,因此低级迭代可以进行预处理,这是然后喂给更高级别的迭代者。

It is part of the Iteratee I/O-handling which Play provides. Iteratees are an interesting beast -- on one hand, it "pushes" data to the handler, instead of relying to the handler to pull data, and, therefore, has better performance. On the other hand, it allows the handler to control when the flow should be stopped. Finally, one can compose iteratees so that different iteratees are responsible for different parts of the input (say, one to receive HTTP headers, other to receive its body) as well as chaining them so low level iteratees can do a pre-processing which is then fed to higher level iteratees.

他们有很多材料,可以利用它。

There's plenty of material on them, avail yourself to it.

它是以任何方式与迭代器或枚举相关。

It is not related in any way to iterators or enumerations.

这篇关于scala和java中的枚举器vs迭代器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆