Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim Tsvetkov committed Jun 18, 2022
1 parent 8e9e248 commit ae05f35
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/algae/internal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,19 @@ defmodule Algae.Internal do
def default_value({{:., _, [String, :t]}, _, _}), do: ""

def default_value({{:., _, [{_, _, adt}, :t]}, _, []}) do
quote do: unquote(Module.concat(adt)).new()
if Kernel.function_exported?(Module.concat(adt), :new, 0) do
quote do: unquote(Module.concat(adt)).new()
else
quote do: nil
end
end

def default_value({{:., _, [module, :t]}, _, []}) do
quote do: unquote(module).new()
if Kernel.function_exported?(module, :new, 0) do
quote do: unquote(module).new()
else
quote do: nil
end
end

def default_value([_]), do: []
Expand Down

0 comments on commit ae05f35

Please sign in to comment.