I tried things like Tuple.to_list and Map.new but I’m not very professional
Unfortunately, I do not know why the api output of one of the sites is like this
Usually you don’t delete information from tuples.
Why would you want to delete “status”? to end up with something like {1},
you simply pattern match and do something with that data.
Think of tuples as a way to return/store information of a fixed shape, for example {:ok, value} or {:error, status, info}
then you pattern match these values and you act accordingly.
def parse() do
case MyModule.get_info() do
{:ok, value} ->
value + 1000
{:error, status, extra_info} ->
raise("Failed with status code: #{status}. Additional information: #{inspect(extra_info}")
end
end
another common function to work with tuples is elem/2, which you use when you care about a particular element in the list, is it commonly used in pipelines when you use the pipe operator |>,
for example.
MyModule.get_info() |> elem(0)
UPDATE: this is used to avoid breaking the pipeline and to avoid pattern matching and storing unnecessary variables, but since you are starting… start with pattern matching until you feel comfortable with it.
I solved my problem with this method
Thanks to all the friends
defmodule R do
def test(input) do
case HTTPoison.post("https://sample.com/", Jason.encode!(%{"user" => input})) do
{:ok, %{body: body, status_code: 200}} ->
Jason.decode!(body)["five_sorted"]
{:error, _} ->
IO.inspect("_")
end
end
end
for dd <- R.test(1) do
IO.puts(dd["down_link"])
end