Stream chunk_by is giving me unexpected behaviour

iex(26)> Stream.chunk_every([1, 2, 3, 4, 5, 6, 7], 2) |> Enum.to_list()
[[1, 2], [3, 4], [5, 6], '\a']

I was expecting the last chunk to be a partial chunk as stated in the docs [7]. How is it not even a list? How can i get the desired behaviour [[1, 2], [3, 4], [5, 6], [7]]?

All characters of your list are printable as text so by default IEx will show them as text. But it is indeed a charlist, a list of printable integers.

iex(1)> '\a' == [7]
true

iex(2)> [0 | 'hello']
[0, 104, 101, 108, 108, 111]

1 Like

Oh i see. Is there anyway i can print the list of integer as list of integer instead of charlist

Yes you can pass that option to inspect/2 or IO.inspect/2:

iex(5)> IO.inspect('hello', charlists: :as_lists, label: "my list")
my list: [104, 101, 108, 108, 111]
'hello'

1 Like