how to remove the filtered
lines from the current streaming file using fs2 and get the count of filtered lines as the return type?
ex: If the old.txt
contains strings separated by a newline (\n):
john
sam
chen
yval
....
and 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()