Elixir Reflection

Thanks for your answer @peerreynders! I took all my time to explore every example, I need to say thanks help me to think more functinal (specially the monads), but sadly I need to say that I still without figure out a final Elixir way for my problem, I’ll explain:

Here is not a problem, I already have my reader/writer for every data over the socket, it basically contains:

  • Message id (unique id for every message, every one has a different work on the server and call for something different) [always an ushort field, integer if its elixir]
  • The message length
  • The rest data, this remain data is used to construct the “module” based on the MessageId, this “module” contains primitive properties and class properties as well (this work in a OO language, but this abstractions can easily move to elixir, simply moving the abstract class to the result module), so here…

…is the problem, the total messages in this case are 1040 without counting the types (Serialized classes inside de message) and the server sends 705 of those messages and recieve 335 from the client, handle the deserializer for all those messages + the handlers for every messages its insane exausting and hard to mantain!

This is an interesting proposal can you give me an example about it? I exactly dont understand what do you mean with “discriminators” on elixir

I’ll keep this in mind after solve the dispatch problem, thanks!


So in summary my problem is “how to construct a module based on a identifier without using a huge case expression (?)” and “how to call a handler (module function) based on this result module (or the message id) without using a huge case expression (again)”


Notes: I just give my previous examples based on my experience on C#, this is the “C# like” way to handle this solution, but now I’m really sure that this is not the solution for Elixir, so I want to know what is the best way here ^^ I did this project specifically to know the amazing Elixir ^^, this challenges are the best to study the language :smiley: (in my opinion ^^), I’m really happy to get answers that makes me learn more about Elixir, thanks!

Greetings!