What I am trying to do is this: I have multiple functions that are almost all the same. Each one gets a thing from an API. Each one is the same, but each one returns a different struct. All of them look like this:
defmodule Thing1Resolver do def get_one(args) do data = get_from_api(args) struct(Thing1, args) end end
The only difference is the module
Thing1 is different for each function (
Thing4). Can I write a macro to
use and build functions like this? So maybe my resolver modules look like
defmodule Thing1Resolver do use Shared, struct: Thing1 end
Is this possible? Maybe it is a bad idea. I want to understand how it works and then I can decide.