2012-12-04 57 views
1

試圖讓我的腦袋繞着玩遊戲2.0.4 - 我想交織一個枚舉器與另一個,但只有第一枚枚舉(獨佔)的長度。 所以:Interleave Enumerators play 2.0

Enumerator("hello", "world") -> "hello" ", " "world" 
Enumerator("one", "two", "three") -> "one" ", " "two" ", " "three" 

內置交織包括過去的第一枚舉結束,直到第二枚舉結束。

val commas : Enumerator[String] = { 
    Enumerator(", ", ", ", ", ") 
} 
val words : Enumerator[String] = { 
    Enumerator("hello", "world!") 
} 
Ok.stream(words interleave commas andThen Enumerator.eof) 

生產 「你好,世界」,而不是 「你好,世界」

幫助非常感謝!

回答

0

Enumerators通常會被處理直到被消耗,所以在您的場景中,結果是預期的,因爲一旦一個枚舉器被清空,另一個枚舉器的其餘部分被處理。

你似乎需要的是一個Iteratee相應地處理輸出和過濾器。您可以在documentation中找到一些示例。

另一種可能的方法是使用一個Enumeratee(見documentation)來轉換的交織的輸出。

+0

謝謝,我一直努力嘗試與Iteratee /枚舉,但這基本上是我的問題。查找文檔有點困難,所以任何指導表示讚賞。 – barnybug