Hi,
I have a function with with
statement:
def validate_all do
with :ok <- validate(:a),
:ok <- validate(:b),
:ok <- validate(:c),
:ok <- validate(:d),
:ok <- validate(:e)
do
IO.inspect "ok"
else
err -> IO.inspect(err)
end
end
That works just fine, but I want to generate with
clauses at compile time depending on config. Right now I’m stuck with something like this:
Not working example:
@validations [:a, :b, :c, :d, :e]
withstatemets = @validations |> Enum.map( fn validation ->
quote do
:ok <- validate(unquote(validation))
end
end
def validate_all do
with unquote(withstatemets) do
do
IO.inspect "ok"
else
err -> IO.inspect(err)
end
end
It this possible?
Thanks for you help!