At the risk of stating the obvious
defmodule Stuff do
defstruct foo: nil, bar: nil
def from_map(%{"foo" => foo, "bar" => bar}),
do: %Stuff{foo: foo, bar: bar}
# alternatively - return some error
def from_map(m),
do: m
#...
end
# ...
def handle_in("send_stuff", stuff, socket) do
with %Stuff{} = my_stuff <- Stuff.from_map(stuff) do
something_with(my_stuff)
else
# do something else with "stuff" argument ...
end
end
# ... or
def handle_in("send_stuff", stuff, socket) do
case Stuff.from_map(stuff) do
%Stuff{} = my_stuff ->
something_with(my_stuff)
# other options ...
_ ->
# ...
end
end






















