This decode as stuff is pretty cool.
So why is it not part of Phoenix? (or am I missing something)
This won’t work:
defmodule Stuff do
defstruct foo: nil, bar: nil
end
def handle_in("send_stuff", %Stuff{} = my_stuff, socket), do: something_with(my_stuff)
The incoming json is already decoded, so I would have to do something like:
def handle_in("send_stuff", %{} = my_stuff, socket) do
my_stuff
|> Poison.encode
|> (fn ({:ok, json}) -> Poison.decode(json, as: %Stuff{}) end).()
|> something_with
end
My solution is to not use structs, which I don’t like, I would love to use structs.
%Stuff{} = my_stuff is a lot more concise than %{"foo" => foo, "bar" => bar}
In case of many parameters, the function definitions become unreadable and ugly,
which is not an enjoyable kind of pattern matching.
Am I missing something?






















