'How to check for a valid guard expression in Elixir?
I would like to write a macro to check if an Elixir expression is a valid guard :
defmacro valid_guard?(expr)
However I could not find anything in the documentation looking for elements to write this piece of code.
I feel like this function should be part of Elixir also but maybe there is a way to plug it in from erlang ?
Solution 1:[1]
One might look into elixir’s source code for defguard/1 in the first place.
One might technically copy-paste the code calling :elixir_utils.extract_guards/1 and check for the outcome instead of doing real work, but I am not sure why this would be ever needed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Aleksei Matiushkin |
