I'm getting input via a query param like this: 127.0.0.1:8000/pair?A=[{A1,B1},{A2,B2},…,{An,Bn}]
. I need to access that list of tuples and alter it, so that the result is a list of two tuples, the first one contains the first elements of each tuple in the original list, and the second tuple contains the second elements of each tuple, (like this [{A1,A2,…,An},{B1,B2,…,Bn}]
) for example:
Input: [{a,5},{2,x},{r,r}]
Output: [{a,2,r},{5,x,r}]
The problem is that if I do:
conn = fetch_query_params(conn)
%{ "A" => input } = conn.query_params
the input variable is then bitstring, so I tried using
input_parsed = :binary.bin_to_list input
, but then if I'm trying to iterate over it like this:
output = Enum.map(input_parsed, fn {x, y} -> {x+y} end)
I'm getting the following errors:
(FunctionClauseError) no function clause matching in anonymous fn/1 in PwZadanie1.Router.do_match/4
(pw_zadanie_1 0.1.0) lib/pw_zadanie1/router.ex:30: anonymous fn(91) in PwZadanie1.Router.do_match/4
(elixir 1.11.3) lib/enum.ex:1411: Enum."-map/2-lists^map/1-0-"/2
91 is [
in ASCII so it's still not parsed.
I'm new to Elixir and would greatly appreciate any help with this. Thank you.