How to convert a stream back to a string?

iex(1)> fun = fn str ->
...(1)>   {:ok, pid} = StringIO.open(str)
...(1)>   pid
...(1)>   |> IO.binstream(1)
...(1)>   |> Stream.filter(&(&1=="e"))
...(1)>   |> Enum.to_list()
...(1)>   |> IO.iodata_to_binary()
...(1)> end
#Function<6.127694169/1 in :erl_eval.expr/5>
iex(2)> fun.("eabcdefge")
"eee"
iex(3)>

IO.iodata_to_binary/1

2 Likes