# Does Enum.chunk\_by have a bug?

**URL:** <https://forum.elixirforum.com/t/does-enum-chunk-by-have-a-bug/67973>\
**Category:** Questions\
**Tags:** bug, chunk\_by\
**Created:** [December 9, 2024, 1:50am UTC](https://forum.elixirforum.com/t/does-enum-chunk-by-have-a-bug/67973 "2024-12-09T01:50:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shjeon0730](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/shjeon0730/32/36885_2.png) [@shjeon0730](https://forum.elixirforum.com/u/shjeon0730)\
**Post date:** [December 9, 2024, 1:50am UTC](https://forum.elixirforum.com/t/does-enum-chunk-by-have-a-bug/67973/1 "2024-12-09T01:50:59Z")

</div>

Hi!  
I am new in Elixir. Still learning syntax. But I I see very weird behavior while I am testing functions.

The question is about `Enum.chunk_by` function.

```elixir
list=[1,2,3,4,5,6,7,8,9,10]
Enum.chunk_by(list, & rem(&1,4)==0)

```

expected result is,

```elixir
[[1,2,3],[4],[5,6,7],[8],[9,10]]

```

but, what I am receiving is

```elixir
[[1, 2, 3], [4], [5, 6, 7], ~c"\b", ~c"\t\n"]

```

My elixir version is 1.17.3, on MacOS 15.1.1, M1 Pro

I am curious if there is some system-relative background of this result.  
Thank you!

===

Answer for this question:  
turned out ~c"\b" is equivalent to [8], and ~c"\t\n" is equivalent to [9,10]  
as the chosen answer explains. This looks like a common mistake that a beginner is confused (like me). Thanks for all the answers! I couldn’t understand the short answers, but after I understand what is happening, even the short answers makes sense.

---

<div class="post-metadata">

**Author:** ![al2o3cr](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/al2o3cr/32/3457_2.png) [@al2o3cr](https://forum.elixirforum.com/u/al2o3cr)\
**Post date:** [December 9, 2024, 1:53am UTC](https://forum.elixirforum.com/t/does-enum-chunk-by-have-a-bug/67973/2 "2024-12-09T01:53:11Z")

</div>

The `~c` sigil indicates a charlist

[https://hexdocs.pm/elixir/binaries-strings-and-charlists.html#charlists](https://hexdocs.pm/elixir/binaries-strings-and-charlists.html#charlists)

---

<div class="post-metadata">

**Author:** ![shjeon0730](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/shjeon0730/32/36885_2.png) [@shjeon0730](https://forum.elixirforum.com/u/shjeon0730)\
**Post date:** [December 9, 2024, 2:49am UTC](https://forum.elixirforum.com/t/does-enum-chunk-by-have-a-bug/67973/3 "2024-12-09T02:49:40Z")

</div>

Hey, @al2o3cr , thanks for taking a look.  
My question is if the result is expected, if so, why?  
As I see the document, it says it should create chunk when callback function returns different value.  
the callback function `& rem(&1,4)==0` will return like this:  
[false, false, false, true, false, false, false, true, false, false]  
because rem(1,4)==1, rem(2,4)==2, rem(3,4)==3, rem(4,4)==0,…  
so, rem(&1,4) will be [1,2,3,0,1,2,3,0,1,2]

But, why ~c"\b" and ~c"\t\n" comes to where [8], [9,10] should be?

---

<div class="post-metadata">

**Author:** ![arcanemachine](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/arcanemachine/32/29109_2.png) [@arcanemachine](https://forum.elixirforum.com/u/arcanemachine)\
**Post date:** [December 9, 2024, 2:55am UTC](https://forum.elixirforum.com/t/does-enum-chunk-by-have-a-bug/67973/4 "2024-12-09T02:55:21Z")

</div>

Check out this post and read the rest of its thread as well:

> [@List append (++) does not return a list](https://forum.elixirforum.com/t/list-append-does-not-return-a-list/66569/6):
>
> IEx.configure(inspect: [charlists: :as\_lists]) Run this manually inside iex or put it in a file called .iex.exs at the root of your project and it will be ran automatically on iex startup in that directory.

---

<div class="post-metadata">

**Author:** ![llama](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/llama/32/23675_2.png) [@llama](https://forum.elixirforum.com/u/llama)\
**Post date:** [December 9, 2024, 3:51am UTC](https://forum.elixirforum.com/t/does-enum-chunk-by-have-a-bug/67973/5 "2024-12-09T03:51:01Z")

</div>

Short answer:

“This is done to ease interoperability with Erlang, even though it may lead to some surprising behavior. For example, if you are storing a list of integers that happen to range between 0 and 127, by default IEx will interpret this as a charlist and it will display the corresponding ASCII characters.”

> **[Binaries, strings, and charlists — Elixir v1.21.0-dev](https://elixir.hexdocs.pm/main/binaries-strings-and-charlists.html)**
