20

Currently, there two popular choices which implement the iteratee pattern:

What are their relative benefits? Is one better than the other, or does it depend on the use-case (and if so, what are the criteria to decide which one to use)?

4

1 回答 1

21

至少有三个迭代库:

  • 枚举器
  • 迭代者
  • 迭代IO

我相信枚举器库是目前首选的,因为它很简单。如果你在乎的话,它也是我用于我的项目的那个。其他两个包更灵活,有时速度更快,但它们也更复杂。如果你想学习 iteratees,我建议从enumerator开始。它是对奥列格最初想法的最直接的实现。

如果您有一个特定的用例并且需要标准 iteratee 方法的许多功能,您可能需要考虑使用iteratee包。在更复杂的场景中,您可能还想尝试iterIO包,它的概念略有不同且更灵活。特别是迭代器可以与枚举器通信,这在其他两个包中是不可能的。

如果这三个包都不够灵活,你可能想用monad-coroutine包自己编写协程。迭代器和枚举器是一种特殊类型的协程,它们可以以某种方式组合。monad-coroutine包为您提供了通用类型,并允许您使用自己的交互概念。

于 2011-10-06T13:41:01.537 回答