holasoymas
I’m encountering a strange issue when using Enum.filter/2 in my Elixir script. The problem occurs when I filter a list with a condition that elements should be greater than a certain value using pipe operator.
pipe_operator.exs
defmodule PipeOperator do
def return_big(list) do
list
|> Enum.map(&(&1 * 2))
|> Enum.filter(&(&1 > 40))
end
end
big = PipeOperator.return_big([2, 5, 20, 30,40])
IO.inspect(big)
EXPECTED RESULT
I expect the output to be a list of elements greater than 40 after they have been doubled. For the input list [2,5,20,30,40] . The doubled list is [4,10,40,60,80] and the filtered list should be [60,80].
ACTUAL RESULT
When I filter with &(&1 > 40), instead of the expected list, I get this strange output in my terminal:
myname@Lenovo-V14-IGL:~/Desktop/learnelixir/modules$ elixir pipe_operator.exs
~c"<P"
myname@Lenovo-V14-IGL:~/Desktop/learnelixir/modules$
and sometime ~c"<Px" , ~c"<\n(<Pdepending the value of list.
However, if I change the filter condition to &(&1 > 2), or 1 it works as expected, and I get the correct filtered list.
Elixir version : Elixir 1.17.0 (compiled with Erlang/OTP 27)
OS : Linux mint 21.2
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
rvnash
IO.inspectis interpreting the list of integers as aCharlist, and rendering it with the~csigil. You can explicitly tellIO.inspectto render the list of integers as a list.See: FAQ · elixir-lang/elixir Wiki · GitHub
dimitarvp
They are exactly the same, the numbers can be interpreted as printable characters so they are shown as such. This setting can be disabled btw.