I have the following function working in an Elixir app:
def emojify(%Conv{status: 200, resp_headers: resp_headers} = conv) do
body = if resp_headers["Content-Type"] == "application/json", do: conv.resp_body, else: "????" <> "\n\n" <> conv.resp_body <> "\n\n" <> "????"
%{ conv | resp_body: body }
end
def emojify(%Conv{} = conv), do: conv
I'd like to refactor it to eliminate the need for the if inside it. I imagine that the way to do it is through pattern matching the content-type inside the resp_headers, but that would be pattern matching of a map inside a map (a struct inside a map to be more precise, but I don't think this detail is relevant in this case), and I'm not sure how to do that.
I was trying something like def emojify(%Conv{status: 200, resp_headers: %{"Content-Type" => "application/json"}} = conv), but I understand that this would only work if resp_headers has only "Content-Type" => "application/json" inside it, and that isn't the case. So how could I accomplish this?
Access. - NobbZ