This looks like a great library!
I was going through the limitations sections but didn’t understand much.
Can you give an example of what is not supported?
This looks like a great library!
I was going through the limitations sections but didn’t understand much.
Can you give an example of what is not supported?
Thank you.
The following user types are not supported: parametrized types @type dict(key, value) :: [{key, value}]
where key
and value
are another types. And self referencing types @type my_type :: [my_type]
.
These are quite rarely used, so if you don’t, it’s ok
new!/1/0
and new/2/1/0
become overridable.Domo.Changeset.validate_type/1
skips has_many
and other assoc fields automatically, so the cast_assoc(:field)
can be called to do the associations validation sequentually.The one validate_type/1
call in the changeset gives a 1.5x slower execution than the bunch of equivalent Ecto’s validate_...
calls.
At the same time, the execution duration of the pure Domo generated constructor function new!/1
is the same as of building a struct with Ecto changeset approach.
Comparison:
Domo Album.new!/1 5.31
Ecto.Changeset validate_.../1 5.21 - 1.02x slower +3.59 ms
Domo.Changeset validate_type/1 3.76 - 1.41x slower +77.93 ms
You can find all benchmark results in the README
The overridable constructors open the remarkable feature of injecting the generated default values into a struct, keeping the values validated. Let the struct using Domo have a token
field, then the generation of the default value can be done like that:
def new!([_|_] = fields) do
super(Keyword.merge(fields, token: random_string(8)))
end
So no matter what random_string
returns, the super function will ensure that it matches the type of the token
field defined in t()
.
Magnificent!
How would one go for recursive types (which is done via @type my_type :: [my_type]
) ?
Say, a tree with nodes / leaves has to be defined. How can types of a leaves/nodes of tree be ensured using Domo?
One way I can think is this. @type node :: :root | [node]
Hey, thanks for your message. The self-referencing struct type suitable for building trees is exactly the case that is not supported by the library yet. PRs are welcome
ResolvePlanner
server for printing verbose debugging messages.name_of_new_function
to gen_constructor_name
. Please, update your project if you use it
new!/1/0
and new/2/1/0
composable instead of overridable, see Custom constructor function section in README.mix deps.update domo
, please, remove .elixir_ls
in your project directory and reopen VSCode.Now struct type checking errors are in the VSCode view
That’s amazing, thank you.