Background
I am trying to find a cheap and easy way to create New Types in Elixir, and Records seem to be just what I would need.
Problem
However, Elixir records require one to define default values. Not only that, it also allows one to create empty records (which would then be populated with said default values).
For my specific use case, this is a problem. Not only don’t I have anything that can be used as a default value, I also don’t want to allow the users of my code to create empty records.
Now, I understand this is likely a well intended choice, most likely so it can interface nicely with Erlang records, but it causes an usability issue on my end: it allows the creation of non valid data.
Questions
I understand there is probably no solution for this conundrum using Records only, so I was wondering if there are alternatives in the wild of libraries or even hacks to accomplish this.
I personally have found nothing, right now I have the feeling my only solution is to write my own macro.
- Is there a way to have Records not accept default values?
- If not, what community libraries are out there that could help fulfill the role of creating a New Type?