Background
I have a list of numbers that can contain nil entries:
iex(52)> test = [54, 54, 54, 56, nil, nil, 56, 56, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 56, 57, 56, 56, 56, 56, 56]
[54, 54, 54, 56, nil, nil, 56, 56, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57,
57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57,
57, 57, 57, 57, 56, 57, 56, 56, 56, 56, 56]
Now, normally I would either use Enum.filter
or Enum.reject
to clean the nil
s out of it. Unfortunately, using it returns the following:
iex(53)> Enum.filter(test, fn n -> n != nil end )
'66688899999999999999999999999999999999999898888&&&&&&&&&&&&&&'
Same happens if I use is_nil
instead of the custom condition.
Questions
- Why is this happening?
- How can I fix it?