如何使用fs2filtered
从当前流文件中删除行并获取过滤行数作为返回类型?
例如:如果old.txt
包含由换行符 (\n) 分隔的字符串:
john
sam
chen
yval
....
和val myList = List("chen","yval")
。
def converter[F[_]](implicit F: Sync[F]): F[Unit] =
io.file.readAll[F](Paths.get("testdata/old.txt"), 4096)
.through(text.utf8Decode)
.through(text.lines)
.filter(s => myList.contains(s))//remove this from the old file and write to new file
.intersperse("\n")
.through(text.utf8Encode)
.through(io.file.writeAll(Paths.get("testdata/new.txt")))
.compile.drain
// at the end of the universe...
val u: Unit = converter[IO].unsafeRunSync()