elixir - List.flatten returns unexpected value -
version: 1.2.2, error:
list.flatten ([a,[b]]) expected return ([a,b]). however, not work cases. example, list.flatten ([11, [[12], 13]]) returns '\v\f\r', when ([11,12,13]) expected. list.flatten([10]) returns '\n'.
why happening , workaround, if any?
as greggreg explained, reason why final list - [11,12,13] - looks '\v\f\r' instead, because contains printable acsii codepoints. hence output charlist.
if need numbers list, instead of characters, here can do:
iex> sample_list = [11,12,13] iex> [first | rest] = sample_list iex> [second | rest] = rest iex> [third | rest] = rest iex> first iex> 11 iex> second iex> 12 iex> third iex> 13
so basically, when taking out number list, being converted integer. since not list, cannot converted charlist.
Comments
Post a Comment