本文翻译自:Scalaz iteratees: “Lifting” `EnumeratorT` to match `IterateeT` for a “bigger” monad
If I have an EnumeratorT and a corresponding IterateeT I can run them together: 如果我有一个EnumeratorT和一个相应的IterateeT我可以一起运行它们:
val en: EnumeratorT[String, Task] = EnumeratorT.enumList(List("a", "b", "c"))
val it: IterateeT[String, Task, Int] = IterateeT.length
(it &= en).run : Task[Int]
If the enumerator monad is "bigger" than the iteratee monad, I can use up or, more generally, Hoist to "lift" the iteratee to match: 如果枚举器monad比iteratee monad“更大”,我可以用up或者更常见的是,使用Hoist “提升”iteratee以匹配:
val en: EnumeratorT[String, Task] = ...
val it: IterateeT[String, Id, Int] = ...
val liftedIt = IterateeT.IterateeTMonadTrans[String].hoist(
implicitly[Task |>=| Id]).apply(it)
(liftedIt &= en).run: Task[Int]
But what do I do when the iteratee monad is "bigger" than the enumerator monad? 但是当iteratee monad比枚举器monad“更大”时,我该怎么办?
val en: EnumeratorT[String, Id] = ...
val it: IterateeT[String, Task, Int] = ...
it &= ???
There doesn't seem to be a Hoist instance for EnumeratorT , nor any obvious "lift" method. 似乎没有EnumeratorT的Hoist实例,也没有任何明显的“提升”方法。
本文探讨了在Scala中使用Scalaz库的EnumeratorT和IterateeT进行数据处理时,如何在不同Monad间进行适配。特别是在枚举器Monad比iteratee Monad“更大”或相反情况下的解决策略。
373

被折叠的 条评论
为什么被折叠?



