2
假設我輸入文件myInput.txt
如下所示:如何合併相鄰的線與scalaz流不失分割線
~~~ text1
bla bla
some more text
~~~ text2
lorem ipsum
~~~ othertext
the wikipedia
entry is not
up to date
也就是說,有通過~~~
分開的文件。期望的輸出如下:
text1: bla bla some more text
text2: lorem ipsum
othertext: the wikipedia entry is not up to date
我該怎麼做?下面似乎很自然的,再加上我失去了冠軍:
val converter: Task[Unit] =
io.linesR("myInput.txt")
.split(line => line.startsWith("~~~"))
.intersperse(Vector("\nNew document: "))
.map(vec => vec.mkString(" "))
.pipe(text.utf8Encode)
.to(io.fileChunkW("flawedOutput.txt"))
.run
converter.run
這不是一個真正的答案,但我得到了[一個小scalaz流分裂庫](https://github.com/travisbrown/syzygist)[使這種事情很容易](https://gist.github.com/travisbrown/42f28afbc0bc4c5ff28a)。 –
@TravisBrown看起來很有趣 – mitchus